#(Java) Learning how to manage multiple Threads

1 messages · Page 1 of 1 (latest)

north wolf
#

I'm trying to figure out how to have multi threads and manage them all properly

honest kindle
#

executorservice ftw

north wolf
#

isShutdown()

#

i'm very new to this

north wolf
#

anyone who have some books or links

north wolf
#
import java.util.ArrayList;
import java.util.List;

public class ThreadManager {

    private List<Thread> threads;

    public ThreadManager() {
        threads = new ArrayList<>();
    }

    public void startThread(Runnable runnable) {
        Thread thread = new Thread(runnable);
        threads.add(thread);
        thread.start();
    }

    public void stopThreads() {
        for (Thread thread : threads) {
            thread.interrupt();
        }
        for (Thread thread : threads) {
            try {
                thread.join();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}
#

(Java) Learning how to manage multiple Threads

north wolf
#

oh feck i forgot to ask chat gpt that

#

i just learned that you get run code inside or outside using thread

honest kindle
#

what

tacit rune
#
north wolf
#

ty for commenting and sharing

tacit rune
#

probably want to learn about:

threads and how they work internally
threadpools
synchronisation
synchronised collections

#

and theres so much more :)

#

just start looking at some basic things

north wolf