Java ExecutorService examples

In Java, we can use ExecutorService to create a thread pool, and tracks the progress of the asynchronous tasks with Future. The ExecutorService accept both Runnable and Callable tasks. Runnable – Return void, nothing. Callable – Return a Future. 1. ExecutorService 1.1 A classic ExecutorService example to create a thread pool with 5 threads, submit …

Read more

Spring and Java Thread example

Here are 3 examples to show you how to do “threading” in Spring. See the code for self-explanatory. 1. Spring + Java Threads example Create a simple Java thread by extending Thread, and managed by Spring’s container via @Component. The bean scope must be “prototype“, so that each request will return a new instance, to …

Read more