Skip to content

Tag: multithreading

Can Java handle 10 Thread pool at the same time

I have a Java Application which handles different region for example 10 regions. Each region have different number of tasks. I encounter a problem is that one particular region (Region A) have lots of tasks and the processing time of each task for that region is very long. Therefore, if I use a Single Thread …

java concurrency vs parallelism

I know the difference between the two clearly. Concurrency is performing multiple tasks alternately, while parallelism is performing multiple tasks at once. However, there is confusion in this code because a certain instructor has a different opinion than me. Here is code: I thought that running this code on …

Locking execution within CompletableFuture

I need to post-process result of CompletableFuture.supplyAsync execution to get intermediate result. My code looks following In a result I’m facing with java.util.concurrent.CompletionException: java.lang.IllegalMonitorStateException on .thenAccept(resultPerBatch -> { line Seems like I’m using …

How to properly null check/lazy load

I have a resource file that I load, when needed, to check if a certain word is among the ones in the file. I want to get rid of the method-wide synchronized keyword. There’s no point in all threads waiting while wordsInFile.contains(word.toLowerCase()); runs. Original: Is this OK? Answer This is a varia…

Why assigning instance variable to local variable?

This is something I see in Spring Boot code for example (in the catch block with webServer variable): Why not just doing this.webServer.stop()? What is the purpose of local variable webServer? Answer The main purpose of the assignment is to avoid producing a NullPointerException when the this.webServer is set…

Calling a Method in a running Thread Object [closed]

Closed. This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 5 months ago. Improve this question I’m a Java beginner. I want to call a Method in a running Java Thre…