Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package watki;
- class Run2 implements Runnable {
- int numer;
- public Run2(int numer ) {
- this.numer = numer;
- }
- @Override
- public void run() {
- System.out.println("Start watek " + numer);
- int i=0;
- while (true) {
- Thread.yield(); // Thread.yield();
- if (Thread.currentThread().isInterrupted()) { /// Thread.currentThread()
- return;
- }
- System.out.println(numer + ". " + i);
- i++;
- }
- }
- }
- public class Main {
- public static void main(String[] args) throws InterruptedException {
- Thread t = new Thread(new Run2(1));
- t.start();
- Thread.sleep(100);
- t.interrupt();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement