Threads in Java threads?
I am currently considering how to design a multithreaded system in Java that needs a lot of network processing and database storage The program will start three basic threads first Along these basic threads, I want to start not from other threads of the main program, but from two threads A thread may start another thread, resulting in a hierarchy, such as:
> Parent ->t0 thread1 -> t1 tread1.1 > ->t0 thread2 > ->t0 thread3 -> t2 thread3.1 t0= inital time t1,t2 = time at a point in the running thread t1 != t2
If no one can provide reference theoretical solutions?
Solution
Yes, you can start as many threads as you need, but this may not be the best way It's better to use a non blocking API so that you can start performing some external calls, and the calling thread can immediately start performing other operations without waiting for the socket / database call to return Then, when the socket / database call returns, a callback is triggered to complete the process
Non blocking I / O can provide far superior CPU utilization because you just trigger calls and register callbacks without trying to balance the "right" number of concurrent threads that are mostly sleeping
http://www.owlmountain.com/tutorials/NonBlockingIo.htm
http://www.tensegrity.hellblazer.com/2008/03/non-blocking-jdbc-non-blocking-servlet-apis-and-other-high-mysteries.html