obasan Posted April 12, 2017 Share Posted April 12, 2017 (edited) I legit don't understand wtf is the point of them. This is the example code: class Loader extends Thread { public void run() { System.out.println(“Hello”); } } class Program { public static void main(String[] args) { Loader load = new Loader(); //load.setPriority(10); load.start(); } } So what's the point of using Threads? Can somebody please explain the usefulness of this? Are threads good because you can optimize the program and spilt the work between two processors? Or maybe they're good because you can change priority and make certain calculations more important than others? Edit: wtf is the runnable interface? I know its another way of creating threads but whats the point? Please & Thank You Edited April 12, 2017 by obasan Quote Link to comment Share on other sites More sharing options...
Final Posted April 12, 2017 Share Posted April 12, 2017 So you posed questions and then answered them for yourself... Maybe you could hire me, do my job for me and still pay me. 3 Quote Link to comment Share on other sites More sharing options...
Polymorphism Posted April 12, 2017 Share Posted April 12, 2017 Ready and study my friend. http://www.javaworld.com/article/2074217/java-concurrency/java-101--understanding-java-threads--part-1--introducing-threads-and-runnables.html https://www3.ntu.edu.sg/home/ehchua/programming/java/j5e_multithreading.html 1 Quote Link to comment Share on other sites More sharing options...
Dex Posted April 12, 2017 Share Posted April 12, 2017 You can implement runnable and still extend from another class. 1 Quote Link to comment Share on other sites More sharing options...
MadDev Posted April 12, 2017 Share Posted April 12, 2017 Imagine if you have a webserver that only operates on 1 thread synchronously. It could only handle one request at a time. Lets say a user visits and another user visits 1 second after, it has to grab his data from the database, do whatever calculations etc, and resolve the first users request before being able to even recognize the second user has sent a request to the website. This is due to the only thread being blocked from the first request, so no other requests can be considered. 1 Quote Link to comment Share on other sites More sharing options...
Reveance Posted April 13, 2017 Share Posted April 13, 2017 The most important thing to understand with threads is that they run concurrently. Imagine you have a program that has a GUI with a button in it. If the button is pressed and you'd execute some heavy calculation (or wait for something) in the same thread (the GUI is running on and being repainted in) ... the whole application would go unresponsive. By using another thread to do the calculation it will keep responsive. It's generally much better to work with Runnables instead of threads as it's much more flexible. Also look up ExecutorService to run them properly. 1 Quote Link to comment Share on other sites More sharing options...
obasan Posted April 14, 2017 Author Share Posted April 14, 2017 On 4/12/2017 at 3:17 PM, Final said: So you posed questions and then answered them for yourself... Maybe you could hire me, do my job for me and still pay me. lol'd. i might just do that ;) Quote Link to comment Share on other sites More sharing options...