简体   繁体   中英

Write Multiple Threads in JAVA

Can we create multiple threads with multiple run methods in a class - 1 run method per 1 thread in JAVA ? I got a response on " Can I have multiple run methods in a class? " but unable to compile the code in this way....

Ok so what you need to do is the following...

Create your classes that you want to run in a thread make sure they implement runnable.

Then in the class that you want to create the threads from you just create a new thread (as many as you want) and pass in a new instance of the runnable class to each thread when you construct it.

Remember to call start on your thread after construction

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM