+ 3
What is thread in Java? What is the use of it?
can any one help me... with a syntax and Simple example
3 Respuestas
+ 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
+ 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
0
thanks