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

CodePudding user response:

reference 1/f, one born in response:
didn't understand what's purpose, 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, call within the b method

Is that the TXT file to read four different directory, want to use multiple threads to read

Don't know feasible,

Thread 1 read a.t xt
Thread 2 read b.t xt
Thread 3 c.t xt
4 read thread which xt

Then put in storage
  • Related