Books, courses and notes

Java Multithreading with Thread API and Executors Framework

February 15, 2017

Hey guys, what's up?


Recently I've been creating more than 20 simple code examples to illustrate how to use the Java API and Executors Framework and I'd like to share it with you and also ask your help to contribute to it forking my GitHub Repository and creating more simple Java Thread examples (Fork/Join Framework simple examples would be very welcome as well).


Some of the subjects already covered in the code examples includes:

  • Running tasks from Thread and Runnable

  • Strategies for returning values from Threads and Runnable tasks

  • wait(), notify(), interrupt(), join(), isAlive()...

  • Creating Thread Pools (FixedThreadPool, CachedThreadPool, SingleThreadPool, ScheduledThreadPool...)

  • Submiting tasks to ExecutorService

  • Returning values from tasks using Callable and Future

  • Naming threads and creating deamon threads in a thread pool implementing ThreadFactory interface

  • Terminating tasks using Thread API

  • Terminating tasks using Future

  • Handling exceptions in normal threads implementing UncaughtExceptionHandler interface

  • Handling exceptions in threads on a thread pool implementing UncaughtExceptionHandler interface

  • Managing tasks termination using CountDownLatch

  • Running scheduled tasks using Timer and TimerTask

  • Running scheduled tasks using ScheduledThreadPool


I hope you enjoy playing with it and let me know if there are any doubts.​


Share on Facebook
Share on Twitter
Please reload

Jorge Acetozi is a software engineer who spends almost his whole day having fun with things such as AWS, CoreOS, Kubernetes, Docker, Terraform, Ansible, Cassandra, Redis, Elasticsearch, Graylog, New Relic, Sensu, Elastic Stack, Fluentd, RabbitMQ, Kafka, Java, Spring, and much more! He loves deploying applications in production while thousands of users are online, monitoring the infrastructure, and acting quickly when monitoring tools decide to challenge his heart’s health!

  • White Facebook Icon
  • White Twitter Icon
  • github-white-icon_edited

November 27, 2017

July 2, 2016

Please reload