Thread thread = new Thread(() -> { //to do }); thread.setName("task"); thread.setDaemon(false); thread.start();