Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package me.bazhenov.bulb;
- public class Main {
- public static void main(String[] args) {
- new Thread(new Bulb("first")).start();
- new Thread(new Bulb("seconds")).start();
- }
- }
- public class Bulb implements Runnable {
- private final String name;
- public Bulb(String name) {
- this.name = name;
- }
- public void run() {
- Thread self = currentThread();
- while(!self.isInterrupted()) {
- System.out.println(name + " bulb is on");
- try {
- sleep(300);
- } catch (InterruptedException e) {
- self.interrupt();
- }
- System.out.println(name + " bulb is off");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement