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



Home Answers Viewqa Development-process Java Thread Synchronization
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


Himaja
Java Thread Synchronization
1 Answer(s)      6 years and 2 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
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
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
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
Advertisements
 

 

 

DMCA.com