Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package multithreading;
- public class Main {
- final static int THREAD_COUNT = 3;
- final static String[] THREAD_NAMES = {"A", "B", "C"};
- public static void main(String[] args) {
- for(int i = 0; i < THREAD_COUNT; i++) {
- Multithreading thread = new Multithreading();
- thread.setName(THREAD_NAMES[i]);
- thread.start();
- }
- }
- }
- class Multithreading extends Thread {
- public void run() {
- int x;
- int sum = 0;
- for(x = 1; x < 9; x++) {
- sum += x;
- }
- sum += x;
- String threadName = Thread.currentThread().getName();
- System.out.println(String.format("Thread : %s - value : %d", threadName, sum));
- }
- }
Add Comment
Please, Sign In to add comment