multi threads

multi threads

View Answers

April 16, 2009 at 10:38 AM

Hi friend,

Code to help in solving the problem :

public class SynchronizedMethod extends Object {
private static int count = 1;
public static synchronized int getCount() {
int i = count;
count++;
return i;
}
private static void print(String msg) {
String threadName = Thread.currentThread().getName();
System.out.println(threadName + ": " + msg);
}
public static void main(String[] args) {
try {
Runnable runnable = new Runnable() {
public void run() {
System.out.println("count=" + getCount());
}
};
Thread threadA = new Thread(runnable, "ThreadA");
threadA.start();
Thread.sleep(500);
Thread threadB = new Thread(runnable, "ThreadB");
threadB.start();
Thread.sleep(500);
Thread threadC = new Thread(runnable, "ThreadC");
threadC.start();
Thread.sleep(500);
Thread threadD = new Thread(runnable, "ThreadD");
threadD.start();
} catch(Exception x ) {}
}
}

Thanks









Related Tutorials/Questions & Answers:
multi threads - Java Beginners
multi threads  Hi i writing a multi threaded program in java .I m using three threads. I want to declare variables which will be available to all the threads to access. Is there a way to declare the variables as global variables
regardoing multi threads - Java Beginners
regardoing multi threads  Hi Please tell me how to declare global variables in main thread so that all other threads can use them and value will be available to all threads. Thanks
Advertisements
implementing an algorithm using multi threads - Java Beginners
implementing an algorithm using multi threads  Hi i need to implement an algorith in multi threads.Algorithm has data dependency so i need to pass... to breakdown into two or three threads and need to implemented and need
threads
threads  what are threads? what is the use in progarmming
threads in java
threads in java  how to read a file in java , split it and write into two different files using threads such that thread is running twice
threads and events
threads and events  Can you explain threads and events in java for me. Thank you.   Java Event Handling Java Thread Examples
Multi Threading
Multi Threading  Hi... I need to solve the following question: Input an array of 10 integers. Separate the odd numbers, even numbers, positive numbers and negative numbers by different threads. I tried to solve it but I dont
Java threads
Java threads  What are the two basic ways in which classes that can be run as threads may be defined
multi threaded program - Java Beginners
multi threaded program  Hi i m developing a multi thread program to execute a real time algorith. I m using three threads. I want to share date between three threads .Is there a way to share data from one thread to another thread
disadvantage of threads
is the disadvantage of threads?   hello,ADS_TO_REPLACE_1 The Main disadvantage of in threads these are operating system dependent.   Hi, Here... the disadvantages of threads. The global variables defined in the application is not thread
Sync Threads
Sync Threads  "If two threads wants to execute a synchronized method in a class, and both threads are using the same instance of the class to invoke the method then only one thread can execute the method at a time." This is what
threads in java
threads in java  iam getting that the local variable is never read in eclipse in main classas:: class Synex4{ public static void main(String args[]){ Test1 ob1=new Test1(); //local variable never read
threads
threads
Threads
Threads
Threads
Threads
Version of cornerstone-threads>cornerstone-threads-api dependency
List of Version of cornerstone-threads>cornerstone-threads-api dependency
Version of cornerstone-threads>cornerstone-threads-impl dependency
List of Version of cornerstone-threads>cornerstone-threads-impl dependency
Version of cornerstone-threads>cornerstone-threads-tutorial dependency
List of Version of cornerstone-threads>cornerstone-threads-tutorial dependency
multi threading code - Java Interview Questions
multi threading code  Hi this is Anji.My question is how to share the variable between two threads?.Can any one post the answer please
Threads in realtime projects
Threads in realtime projects  Explain where we use threads in realtime projects with example
Multi-Threading - Java Beginners
Multi-Threading  Consider a producer process prime-generator produces prime numbers randomly that are displayed by a consumer process called prime... threads for the producer/consumer processes and call them randomly
ModuleNotFoundError: No module named 'threads'
ModuleNotFoundError: No module named 'threads'  Hi, My Python... 'threads' How to remove the ModuleNotFoundError: No module named 'threads... to install padas library. You can install threads python with following command
Java multi-threading
Java multi-threading  What is multi-threading
Coding for life cycle in threads
Coding for life cycle in threads  program for life cycle in threads
Java - Threads in Java
. If your computer does not have multi-processors then the multi-threads really do... Java - Threads in Java       Thread is the feature of mostly languages including Java. Threads
Version of cornerstone-threads-api>cornerstone-threads-api dependency
List of Version of cornerstone-threads-api>cornerstone-threads-api dependency
Version of cornerstone-threads-impl>cornerstone-threads-impl dependency
List of Version of cornerstone-threads-impl>cornerstone-threads-impl dependency
Version of cornerstone-threads-tutorial>cornerstone-threads-tutorial dependency
List of Version of cornerstone-threads-tutorial>cornerstone-threads-tutorial dependency
multi language
multi language  Hello friends please help me Hi how can i do a java program using swing that changes the language like malayalam/tamil etc with languages on a drop down menu I am using netbeans IDE
multi thread
multi thread   Multiple Clients Connect to a server and communicate among the themselves. When a new Client is connected to the server, all other clients get the notification and they can chat with each other. Similarly when
Synchronized Threads
Synchronized Threads       In Java, the threads are executed independently to each other. These types of threads are called as asynchronous threads. But there are two problems may
interfaces,exceptions,threads
with multiple threads is referred to as a multi-threaded process. In Java Programming... THE COMPLETE CONEPTS OF INTERFACES,EXCEPTIONS,THREADS   Interface...: Exception Handling in Java   Threads A thread is a lightweight process which
Examples on threads and mulithreading.....
Examples on threads and mulithreading.....  Is any good examples on threads and Mulithreading...   Hi Friend, Please visit the following link:ADS_TO_REPLACE_1 Thread Tutorial Thanks
multi dimension
multi dimension  class TwoDAgain{ public static void main(String args[]){ int twoD[][]=new int[4][]; twoD[0]= new int[1]; twoD[1]= new int[2]; twoD[2]= new int[3]; twoD[3]= new int[4]; int i, j, k = 0; for (i=0; i<4; i
Multi window
Multi window  I am making a bank app using struts 1.2. using only the struts tags and nno jsp tags and scriplets. db connected thru dao. 1st page contains all the details. when i submit this page, a new window opens and asks
Explain about threads:how to start program in threads?
Explain about threads:how to start program in threads?  import...; Learn Threads   Thread is a path of execution of a program... more than one thread. Every program has at least one thread. Threads are used
java threads - Java Beginners
java threads  What are the two basic ways in which classes that can be run as threads may be defined
Artifacts of cornerstone-threads
List of Artifacts of cornerstone-threads maven depenency
Artifacts of cornerstone-threads-api
List of Artifacts of cornerstone-threads-api maven depenency
Artifacts of cornerstone-threads-impl
List of Artifacts of cornerstone-threads-impl maven depenency
Artifacts of cornerstone-threads-tutorial
List of Artifacts of cornerstone-threads-tutorial maven depenency
Synchronized Threads
Synchronized Threads       In Java, the threads are executed independently to each other. These types of threads are called as asynchronous threads. But there are two problems may
Synchronized Threads
Synchronized Threads       In Java, the threads are executed independently to each other. These types of threads are called as asynchronous threads. But there are two problems may
threads in java - Java Beginners
threads in java  what is the difference between preemptive scheduling and time slicing?   hi friend, In Preemptive scheduling, a thread... or the priority of one of the waiting threads is increased. While in Time Slicing
Java Threads - Java Beginners
allows the threads to wait for resources to become available and also notify the thread that makes resource available to notify other threads
what is multi-threading .?
what is multi-threading .?   what is multi-threading.what is the use in real time, with example programs
Daemon Threads
Daemon Threads       In Java, any thread can be a Daemon thread. Daemon threads are like a service providers for other threads or objects running in the same process as the daemon

Ads