+ 2

Threads? What does it mean...

class hii extends Thread { public void run() { System.out.println("Hello"); } } class MyClass { public static void main(String[ ] args) { hii obj = new hii (); // ^^^ What does this line do? obj.start(); } } // Why use threads? // Wouldn't it work just fine without threads?

29th Nov 2017, 12:47 AM
Rizan
Rizan - avatar
2 Answers
+ 3
I think of threads like hands. I can work with more than one thing at the same time with the more hands that I have. Basically, threading allows you to create additional processes within a process.
29th Nov 2017, 12:55 AM
AgentSmith
+ 1
Typical situations are background processes. Like calculations, database access. Anything that takes long. You don't want to stop your program till that is finished. So execute them on another thread.
29th Nov 2017, 6:27 AM
1of3
1of3 - avatar