Home > Back-end > Java thread thread on how to perform different function
Java thread thread on how to perform different function
Time:05-09
As title, novice please myself
Want to use different thread thread they perform different functions
Thread 1 executive function a Thread 2 executive function b
Should be how to write,,,
CodePudding user response:
Didn't know what's purpose, it is through the condition judgment, 0: open thread 1, perform a, 1: open a thread 2, b? Create two classes A and B, realize the Runnable interface If condition of 0 new Thread (A). The start () and executive function A If conditions for a new Thread (B). The start () and executive function B A and b, if the function must be placed in the same class C, will the function name as a or b threadName handed in, in the start () C threadName, if is a, call inside a method, if is b, b method within the call