Last active
December 27, 2015 05:39
-
-
Save sithu/7275635 to your computer and use it in GitHub Desktop.
Processing a task using a background thread via ExecutorService
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package example.pubsub; | |
import java.util.concurrent.ExecutorService; | |
import java.util.concurrent.Executors; | |
public class BackgroundThread { | |
public static void main(String[] args) { | |
int numThreads = 1; | |
ExecutorService executor = Executors.newFixedThreadPool(numThreads); | |
Runnable backgroundTask = new Runnable() { | |
@Override | |
public void run() { | |
System.out.println("Hello World"); | |
} | |
}; | |
System.out.println("About to submit the background task"); | |
executor.execute(backgroundTask); | |
System.out.println("Submitted the background task"); | |
executor.shutdown(); | |
System.out.println("Finished the background task"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment