Share on Google+Share on Google+

multi threads
1 Answer(s)      8 years ago
Posted in : Java Beginners


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;
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");
Thread threadB = new Thread(runnable, "ThreadB");
Thread threadC = new Thread(runnable, "ThreadC");
Thread threadD = new Thread(runnable, "ThreadD");
} catch(Exception x ) {}


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
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  what are threads? what is the use in progarmming
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
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
threads and events
threads and events  Can you explain threads and events in java for me. Thank you.   Java Event Handling Java Thread Examples
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
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
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
Java threads
Java threads  What are the two basic ways in which classes that can be run as threads may be defined
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
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
disadvantage of threads
is the disadvantage of threads?   hello, The Main disadvantage of in threads... disadvantage of Threads. Let?s discuss the disadvantages of threads. The global..., the other threads using the same memory location will be killed automatically
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
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
Java multi-threading
Java multi-threading  What is multi-threading
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
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
what is multi-threading .?
what is multi-threading .?   what is multi-threading.what is the use in real time, with example programs
Threads in realtime projects
Threads in realtime projects  Explain where we use threads in realtime projects with example
Java multi-threading
Java multi-threading  How does multithreading take place on a computer with a single CPU
Java multi-threading
Java multi-threading  What method is invoked to cause an object to begin executing as a separate thread
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
Coding for life cycle in threads
Coding for life cycle in threads  program for life cycle in threads
Java Spring Hibernate Struts Training Retrieve database from the table dynamically in jsp from oracle using servlet What does core Java include? java What are some way to learn Java quickly? Is it required to learn Java before learning Java Script? Is it necessary to learn java script before learning PHP? Are HTML5 and Java Script boosts Java career? Is Java object oriented? Fingerprint application with Java Uninstall Oracle Virtual Box JSON to HashMap Free Java online Training I want example of Control Statement in Java ANSI Color Codes with Python Create a Program that Calculates Input What is difference between JDK,JRE and JVM? How to see ubuntu version on server? How to get Page Source in Selenium (WebDriver) using Java? The path to the driver executable must be set by the webdriver.gecko.driver system property parse data from a link in java Java Program Qns using BlueJ How to fix HAX Kernel Module Is Not Installed error? Installing Audacity Looking for code Logic to check track changes & Coments in MSWord, MSWordx, MSExcel, MSExcelx is ON/OFF Installing JDK on Mac SAX Parser exception ERROR 601 (42P00): Syntax error. Encountered Thread java.lang.NoClassDefFoundError: org/apache/commons/fileupload/FileItemFactory How to install Ubuntu 16.04 LTS? HttpServletRequest cannot be resolved to a type in eclipse - Solved Unhandled event loop exception GC overhead limit exceeded Spring Data jpa with apache phoenix Caused by: java.lang.IllegalArgumentException: Not a host:port pair: PBUF o.a.h.h.z.RecoverableZooKeeper - Possibly transient ZooKeeper, quorum= com.thinkaurelius.titan.diskstorage.hbase.HBaseStoreManager class not found com.thinkaurelius.titan.diskstorage.hbase.HBaseStoreManager not found How to download and install Java 8 on Windows? How to uninstall JDK 7? How to install gtk-doc-tools package in Ubuntu? How to install Oracle JDK 8 on Ubuntu? ejabberd_ctl.beam not found - Solved How to convert date to UTC format in Java? How to install autoconf, automake and libtool in Ubuntu 15.10? How to convert current date to mm dd yyyy format in Java? How to convert current date to dd mm yyyy format in Java? How to stop window closing in "internalFrameClosing" event. How to find list of all index in Neo4j? file location SASLError using PLAIN: not-authorized


Advertisement null