I'm beginner into the Java Thread Programming and I've read many hours on the subject without found my issue. I hope somebody can help me. My problem is: what is the best way to create non synchronised and non-blocking threads. Per example.
I have a short class A who I need access to his Getter. So i defined
I defined a class thread container
My reader need to read until the readLine() = true but that's still block the while of my two others threads. I have to press severals <ENTER> to unlock my other threads and execute their loop. By reading the Oracle Java Doc API, the object ConcurrentHashMap aren't a blockable object queue.
A hash table supporting full concurrency of retrievals and adjustable expected concurrency for updates. This class obeys the same functional specification as Hashtable, and includes versions of methods corresponding to each method of Hashtable. However, even though all operations are thread-safe, retrieval operations do not entail locking, and there is not any support for locking the entire table in a way that prevents all access. This class is fully interoperable with Hashtable in programs that rely on its thread safety but not on its synchronization details.
The best world IS HAVING my two Class_A can return a value into a LinkedQueue and the queued element are care by the ThreadContainer.
Mabe I made something wrong, dont use the correct class/object or simply have to run my class_C4(destruct_my_brain).run()
No seriously, I realy need help. I'm completely upsets and will very soon turn this project in C++ ;) but I need the Java portability so...
Thanks in advanced
I assume that this section of code is running in such a tight loop that the main thread never yields to allow the other two threads to run. Throw a Thread.sleep(100) in the loop and see if that affects your outcome.
Can we add a king of Timeout to the Readline() method???