Good day. How to make the methods that are in a particular class run in a separate thread?


extends Thread 

won't it help?

  • four
    Do I need to make each method call asynchronously in a separate thread? The result of the call is needed? - Nishi

2 answers 2

Check out https://docs.oracle.com/javase/7/docs/api/java/util/concurrent/Callable.html

description and example here: http://cybern.ru/urok-4-vozvrat-znachenij-iz-zadach-interfejs-callable.html

  • to help your answer, it is advisable to translate into Russian, because Russian-speaking community - lexxl
  • cybern.ru/… - Anton Grebenets
  • the content of external links is desirable to duplicate in response, link may be / become unavailable. also it will simplify the search for the answer for the author of the question - lexxl
  • Please try to publish detailed answers containing a specific example of the minimum solution, supplementing them with a link to the source. Answers –references (like comments) do not add knowledge to Runet. - Nicolas Chabanovsky
  • Thanks for the link, there are a lot of useful things there) - MrTrojan

You need to transfer the object of your class to the Threads class constructor, then override the run () method, in which you will call your methods. Either implement the Runnable interface and also redefine the run () method (better option with Runnable, since you may need to inherit your class from another class).