Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Development-process Java Thread Synchronization

Have Programming Question? Ask it here!
 
 
 


Himaja
Java Thread Synchronization
1 Answer(s)      5 years and 9 months ago
Posted in : Development process



Advertisement
View Answers

November 14, 2008 at 1:50 AM


Hi friend,

Code to solve the problem :

import java.io.*;
class Share extends Thread{
static String msg[]={"This", "is", "a", "synchronized", "variable"};
Share(String threadname){
super(threadname);
}
public void run(){
display(getName());
}
public synchronized void display(String threadN){
for(int i=0;i<=4;i++)
System.out.println(threadN+msg[i]);
try{
this.sleep(1000);
}catch(Exception e){}
}
}
public class SynThread1 {
public static void main(String[] args) throws IOException {
InputStreamReader isr = new InputStreamReader(System.in);
BufferedReader bufReader = new BufferedReader(isr);
System.out.println("Press key enter");
bufReader.readLine();
Share t1=new Share("Thread One: ");
t1.start();
System.out.println("Press key enter");
bufReader.readLine();
Share t2=new Share("Thread Two: ");
t2.start();
}
}

For more information on Java visit to :

http://www.roseindia.net/java/

Thanks


Related Tutorials/Questions & Answers:
Thread Synchronization in Java
Thread Synchronization in Java Sometimes, when two or more threads need shared... as thread synchronization. The thread synchronization is achieved through... to be synchronized } Object in Java which have synchronization block
Java :Thread Synchronization
Java :Thread Synchronization This section explains how to use concept of synchronization in java Thread. Thread Synchronization : . Java supports multi... of program. So for the multi-threaded application, synchronization of java
Advertisements
Java Thread Synchronization - Development process
Java Thread Synchronization  Hi,Please help me with this coding. I... press any key on the keyboard,then one thread must stop.When I press the keys second time,then the second thread must stop. Please provide me with the code  
java synchronization
java synchronization   What is synchronization and why is it important
Java Synchronization
Java Synchronization  What is synchronization and why is it important?  Synchronization is best use with the Multi-Threading in Java. Synchronization is the way to make our program safe. As we know when we have two
Java synchronization
Java synchronization  What is synchronization and why is it important?  Synchronization is best use with the Multi-Threading in Java. Synchronization is the way to make our program safe. As we know when we have two
Synchronization with Multithreading - Java Beginners
information on Thread visit to : http://www.roseindia.net/java/thread/SynchronizedThreads.shtml http://www.roseindia.net/java/thread/ Thanks...Synchronization with Multithreading   Hi Deepak, what
Synchronization in java with example
Synchronization in java with example In this section we will discuss about Synchronization in java. Since java is a multi-threaded language so, when two... synchronization. Synchronized keyword in java create a critical section in which a lock
Synchronization and Singlethreadmodel - Java Beginners
Synchronization and Singlethreadmodel   Hi Deepak, wat is d difference between singleThreadmodel and synchronization. Thank u in advance
Synchronization - Java Beginners
the following links: http://www.roseindia.net/java/thread/synchronization.shtml http...://www.roseindia.net/java/thread/SynchronizedThreads.shtml Thanks... then the accessing thread is going to get the object lock to the whole class or lock is given
Synchronization - Java Interview Questions
Synchronization  Dear Sir my doubt is If we cannot use synchronization for a class then how a vector class is called as synchronized
Synchronization
Synchronization  what is the use of synchronization
synchronization
synchronization  what is about static method synchronization&instance method synchronization
Synchronization
Synchronization  i want code for synchronization using in jsp and servlets
how the streams provide synchronization - Java Beginners
how the streams provide synchronization  How the java streams provides synchronization
java Thread
java Thread  what is purpose of Thread
Java thread
Java thread  How can a dead thread be restarted?  A dead thread cannot be restarted
Java thread
Java thread  What are the high-level thread states
Java thread
Java thread  What are the ways in which you can instantiate a thread
Java thread
Java thread  What invokes a thread's run() method
Java thread
Java thread  What is the difference between process and thread
Java thread
Java thread  What's the difference between a thread's start() and run() methods
Synchronization probleam - Java Server Faces Questions
Synchronization probleam   Hi friends My java multithreading... = new ClientWorker(server.accept(), textArea); Thread t = new Thread(w... //program terminates and thread exits try{ server.close
Synchronization probleam - Java Server Faces Questions
Synchronization probleam  Hi friend my question is why...{ w = new ClientWorker(server.accept(), textArea); Thread t = new Thread(w); t.start(); } catch (IOException e
Java thread
Java thread  Why do threads block on I/O?   When a thread... and in that time some other thread which is not waiting for that IO gets a chance to execute.If any input is not available to the thread which got suspended for IO
Synchronization
Synchronization      ... efficient, but makes two kinds of problems: thread interference and memory consistency errors. By the synchronization tool we can avoid this problem. In other
Thread in java
Thread in java  which method will defined in thread class
Java Thread : getState() Example
Java Thread : getState() Example This section explains how to get state of a thread  in java Thread. Thread  getState() : Suppose you want to know the state of the thread so for that Java Thread provides Thread.getState
Java thread
Java thread  What is the use of serializable
Java thread
Java thread  What method must be implemented by all threads
Java thread
Java thread  What is the difference between wait() and sleep method
Java thread
Java thread  Can we have run() method directly without start() method in threads
Java Thread and Runnable
Java Thread and Runnable  What's the difference between Thread and Runnable types
How to Differenciate Main Thread and Child Thread in Java
Main Thread and Java Child Thread. Please Suggest any example or online link... in Java Programming Language. These are Java Main Thread and the Child Thread. The Below reference will provides you clear idea of java thread concept. http
Synchronization and interlocking
Synchronization and interlocking  What are the different level locking using the synchronization keyword
Java thread state
Java thread state  what is Static binding
Thread - Java Beginners
the concept of thread, thread creation and use of threads in JAVA application?  Thread creation and use of threads in JAVA Java Resourcehttp://www.roseindia.net/java/thread/thread-creation.shtml
how to destroy java thread
how to destroy java thread  how to destroy java thread?   This will help .. Shutting Down the Java Thread
Java thread lock
Java thread lock  What happens when a thread cannot acquire a lock on an object
Java thread state
Java thread state  Difference between sleep and suspend
Java thread state
Java thread state  What is the difference between yielding and sleeping
Java Thread
Java Thread In this tutorial we will discuss about Java Thread. Java Thread : A thread is light weight java program.JVM permits you to have multiple threads for concurrent execution. Each thread has priority. You can also set
thread - Java Beginners
thread  can i asko for programs in thread method that will allow user to input two separate names  Hi friend, For more information on Thread visit to : http://www.roseindia.net/java/thread/index.shtml Thanks
Java Thread
Java Thread Tutorials In this tutorial we will learn java Threads in detail. The Java Thread class helps the programmer to develop the threaded application in Java. Thread is simple path of execution of a program. The Java Virtual Machine
Daemon thread - Java Beginners
information, visit the following link: http://www.roseindia.net/java/thread...Daemon thread  Hi, What is a daemon thread? Please provide me... thread which run in background. like garbadge collection thread. Thanks 
Describe synchronization in respect to multithreading.
Describe synchronization in respect to multithreading.  Hi, Describe synchronization in respect to multithreading. thanks,   Are you eager the search related to Java programming query. Let us check
Java Thread - Java Beginners
and simple examples of "Multithreading". 1. http://www.roseindia.net/java/thread/index.shtml 2. http://www.roseindia.net/java/thread...Java Thread  hii i feel confusion in tread. i want to know about 1
JAVA THREAD - Java Beginners
JAVA THREAD  hii i wrote a pgm to print the numbers from 0 to 9 in 2...); } public void fgh(int i,int p) { int sum; new Thread(public void run... Thread { private static int sums; public static int getSums
Extending thread - Java Beginners
visit to : http://www.roseindia.net/java/thread/index.shtml Thanks...Extending thread  what is a thread & give me the programm of exeucte the thread   Hi friend, Thread : A thread is a lightweight
java thread program
java thread program  write a java program to find out all the current running thread in a java program   public class RunningThreads...() + ":" + group.getClass()+"]"); int count = group.activeCount(); Thread[] threads
Advertisements
 

 

 

DMCA.com