Tag Info

New answers tagged

0

This can easily be done using Thread.wait() and Thread.notify() methods.Do the following from the thread which you want to run ThreadYouWantToWait.wait(); Once the work in done and you want to run the other thread all you need to do is ThreadYouWantToWait.notify(); Hope this helps.


1

Java comes with a CyclicBarrier out of the box. This does exactly what you need, you initialize with the number of threads that need to synchronize and have each call await() to make them wait for all the others.


3

For me it seems pretty straightforward - as you say, you can divide the work beforehand to N chunks, each thread will pick up and process their assigned elements and put to pre-determined place in the array - threads effectively won't read/write same data. Two things though: You should preallocate all the arrays accessed by multiple threads before hand to ...


-2

Well this is a nice question and I think most of the developers who work in web application development don't use multithreading explicitly. The reason is quite obvious since you are using a application server to deploy your application, the application server internally manages a thread pool for incoming requests. Then why use multithrading explicitly? ...


0

It seems most of the answers here mistake this question as "how do I automatically detect race conditions?" when the question is really "how do I reproduce race conditions in testing when I find them?" The way to do it is to introduce synchronization in your code that are used for testing only. For example, if a race condition occurs when Event X happens in ...



Top 50 recent answers are included