Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@kaushikgopal
Created June 25, 2016 21:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kaushikgopal/859db79a6d1519a92dff0dcb7c3ce9cd to your computer and use it in GitHub Desktop.
Save kaushikgopal/859db79a6d1519a92dff0dcb7c3ce9cd to your computer and use it in GitHub Desktop.
Blog post snippet primer on threading
// Version 1
public class IAmAThread extends Thread {
public IAmAThread() {
super("IAmAThread");
}
@Override
public void run() {
// your code (sequence of instructions)
}
}
// to execute this sequence of instructions in a separate thread.
new IAmAThread().start();
// Version 2
public class IAmARunnable implements Runnable {
@Override
public void run() {
// your code (sequence of instructions)
}
}
// to execute this sequence of instructions in a separate thread.
IAmARunnable myRunnable = new IAmARunnable();
new Thread(myRunnable).start();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment