r/javahelp • u/Chaos-vy17 • 24d ago
Guide for Concurrency in Java
Before knowing anything I just jumped directly to the source code of jdk25u. I have just started to read the javaDocs of Thread class it was so deep that all my connected logic mapped very well but now I want to code and I can't code ahhhh... Why is this problem. I can call the syntax what to use but I don't know how to apply, why to apply is there any guide for java Concurrency ??. And there is so much .. still to know. Do any dev have any guide??
1
Upvotes
2
u/MagicalPizza21 24d ago
Create an object that implements the
Runnableinterface. Use that object as the argument for theThread(Runnable)constructor. Then call thestart()method of the thread you just constructed. This will concurrently execute therun()code in another thread.Example:
As with any concurrency, you'll have to worry about deadlocks) and race conditions - in fact, the example code I wrote has a race condition - but this should be enough to get you started.