Skip to content

jiacheng-0/JavaProject-MultiThreading

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Java threads 🧵 https://www.youtube.com/watch?v=a_LBuCx1KTE

image

Code snippets

Via Thread

MyThread thread1 = new MyThread();
thread1.start();
MyThread implementation
public class MyThread extends Thread {  
    @Override  
    public void run() {  
		try {  
			// ....
			Thread.sleep(1000);  
		} catch (InterruptedException e) {  
			e.printStackTrace();  
		}  
        System.out.println("Thread #1 is finished :)");  
    }  
}

Via Runnable

MyRunnable runnable1 = new MyRunnable();  
Thread thread2 = new Thread(runnable1);
thread2.start();
Runnable Implementation
public class MyRunnable implements Runnable {  
    @Override  
    public void run() {  
		System.out.println("Thread #2 : " + i);  
		try {  
			// ....
			Thread.sleep(1000);  
		} catch (InterruptedException e) {  
			e.printStackTrace();  
		}
        System.out.println("Thread #2 is finished :)");  
    }  
}

About

concurrency and multi-threading in Java

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages