DEV Community

dneutr0n
dneutr0n

Posted on

what are the java threading issues? how to reproduce them?

Top comments (4)

Collapse
 
perkinsjr profile image
James Perkins

Threading issues are very difficult to reproduce, which is one of the reason you should design the application to minimize these issues. Immutable objects are your friend. Try to keep mutable objects to single threads and then carefully make sure that when exchanging it between threads is handled well. Think handing the object over to another thread vs lets share. If you need to share make sure they are fully synchronized objects.

Live locks - Are quite difficult to debug the way to debug them is tail your logs whilst the application is running and see them.

Deadlocks - A little easier to debug, you can get a stack trace when deadlocked. Then you can trace that back to the code and redesign the problem. The only problem is you may not get the same results twice but overall it should be fairly obvious.

Race conditons - Use something like ThreadSafe They are incredible difficult to detect usually you would find them in code review without pushing them live however sometimes they sneak through. Using Threadsafe can help with the detection whilst coding.

hope this help!

Collapse
 
dneutr0n profile image
dneutr0n

Thanks it is helpful

Collapse
 
jamesmh profile image
James Hickey

I think you really need to understand how threads work (in general), concurrency theory, etc.

Multi-threading is hard 😜

I would focus on the theory and not necessarily Java in particular. Once you've got that down then start applying it to Java?

Collapse
 
dneutr0n profile image
dneutr0n

Thanks ,Yes theory ll be very helpful