From the course: Kotlin Essential Training: Object-Oriented and Async Code
Unlock this course with a free trial
Join today to access over 25,300 courses taught by industry experts.
Threads, thread pools, and executors - Kotlin Tutorial
From the course: Kotlin Essential Training: Object-Oriented and Async Code
Threads, thread pools, and executors
- [Instructor] Writing multi-threaded code is one of the biggest challenges in software development. Part of the challenge is choosing which sets of APIs and abstractions to work with. In Kotlin, we have several options and we're going to start by reviewing core concurrency APIs from Java that are still available and viable in our Kotlin code. Threads are fundamental elements of concurrency in Java or Kotlin programs. A thread represents a thread of execution by the processor. Having multiple threads can allow for multiple instructions to be carried out in parallel. To create a thread, we can extend the thread class. So here we'll create a class named custom thread and it will extend the thread class. Now within our custom thread, we can override the run method to define what work should be executed when the thread is started. In this case, we simply want to print out a message indicating that our code is running from…