Created
June 25, 2016 21:39
-
-
Save kaushikgopal/859db79a6d1519a92dff0dcb7c3ce9cd to your computer and use it in GitHub Desktop.
Blog post snippet primer on threading
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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