Java background task

I was wondering what would be the most efficient approach for implementing some kind of background task in java (I assume that it will be some kind of non-blocking Threads). To be more precise - I have Java code, and then at some point I need to perform a lengthy operation. What I would like to do is to execute this operation in the background so that the rest of the program can continue execution, and when this task is completed, just update some specific object that is. This change will then be detected by other components.

+5
source share
5 answers

; , , :

// some code
new Thread(new Runnable() {
    @Override public void run() {
        // do stuff in this thread
    }
}).start();

:

public class MyWorker extends Thread {
    public void run() {
        // do stuff in this thread
    }
}

// some code
new MyWorker().start();
+6

. Daemon. JVM , .

0

: Thread,

  • .
  • , parrallel

,

-1

Yes, you will want to unscrew the operation to your own thread. Adding new threads can be a little dangerous if you are not careful and understand what this means and how the resources will interact. Here is a good introduction to the topics to help you get started.

-1
source

All Articles