daily pastebin goal
36%
SHARE
TWEET

Untitled

a guest Oct 23rd, 2018 65 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package multithreading;
  2.  
  3. public class Main {
  4.  
  5.     final static int THREAD_COUNT = 3;
  6.     final static String[] THREAD_NAMES = {"A", "B", "C"};
  7.    
  8.     public static void main(String[] args) {
  9.        
  10.         for(int i = 0; i < THREAD_COUNT; i++) {
  11.             Multithreading thread = new Multithreading();
  12.             thread.setName(THREAD_NAMES[i]);
  13.             thread.start();
  14.         }
  15.     }
  16. }
  17.  
  18. class Multithreading extends Thread {
  19.    
  20.     public void run() {
  21.        
  22.         int x;
  23.         int sum = 0;
  24.         for(x = 1; x < 9; x++) {
  25.             sum += x;
  26.         }
  27.         sum += x;
  28.        
  29.         String threadName = Thread.currentThread().getName();
  30.         System.out.println(String.format("Thread : %s - value : %d", threadName, sum));
  31.     }
  32. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top