What is thread in Java? What is the use of it? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 3

What is thread in Java? What is the use of it?

can any one help me... with a syntax and Simple example

24th Aug 2017, 3:09 AM
Sreejith P
Sreejith P - avatar
3 Answers
+ 3
A thread is just really a way to do multiple things at once in parallel for example thread 1 can be updating the status of a game while thread 2 is rendering it. if one freezes for some reason the other will not stop. it will continue as normal the best example is in minecraft. when server thread stops, the game does not crash. you can still move around. not only of that advantage, when something is in multiple threads, it usally runs faster(depends on the situation). threads can still interact with the same instances of objects as well as the same statc methods. hope this helps happy coding edit*** i will add an example code to this soon with the 2 main ways of creating a thread
27th Sep 2017, 12:20 PM
SomeoneAwesome78
SomeoneAwesome78 - avatar
+ 2
continuation of last response here is the code demo to creating threads note: the code is not meant to be run it is only a demo https://code.sololearn.com/cuQCFYg8BHvA/?ref=app sidenote: implementing runnable is perfered so that you can extend from another class happy coding
27th Sep 2017, 3:20 PM
SomeoneAwesome78
SomeoneAwesome78 - avatar
0
thanks
15th Feb 2019, 8:09 AM
yajat anand
yajat anand - avatar