Hey guys. So, I have yet to truly know how to properly stop a thread. Thus, I have an example and I am wondering if I am stopping the thread the correct way. I would also like to know, can you call .start on a stopped thread to restart it?
Heres the example:
package com.sci; import com.sci.rpi.api.RaspberryPi; public class RPI implements Runnable { private Thread thread; private boolean running; public RPI() { thread = new Thread(this); } public void onStartup() throws Exception { running = true; thread.start(); } public void onShutdown() throws Exception { running = false; thread.join(); } @Override public void run() { while(running) { //do things that are fun and useful } } }