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



Home Answers Viewqa Java-Beginners wap for multithreading
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


neeraj
wap for multithreading
1 Answer(s)      4 years and a month ago
Posted in : Java Beginners


wap for multithreading


Advertisement
View Answers

November 26, 2010 at 10:56 AM


Hi Friend,

Try the following code:

class Multithreading {
int val;
boolean value = false;
synchronized int get() {
if(!value)
try {
wait();
} catch(Exception e) {
System.out.println(e);
}
System.out.println("Get: " + val);
value = false;
notify();
return val;
}
synchronized void put(int val) {
if(value)
try {
wait();
} catch(Exception e) {
System.out.println(e);
}
this.val = val;
value = true;
System.out.println("Put: " + val);
notify();
}
}

class Producer implements Runnable {
Multithreading th;
Producer(Multithreading th) {
this.th = th;
new Thread(this, "Producer").start();
}
public void run() {
int i = 0;
while(i<=50) {
th.put(i++);
}
}
}

class Consumer implements Runnable {
Multithreading th;
Consumer(Multithreading th) {
this.th = th;
new Thread(this, "Consumer").start();
}
public void run() {
while(true) {
th.get();
}
}
}
class ProducerConsumer {
public static void main(String args[]) {
Multithreading th = new Multithreading();
new Producer(th);
new Consumer(th);
}
}

Thanks



Related Tutorials/Questions & Answers:
wap for multithreading
wap for multithreading  wap for multithreading   Hi Friend, Try the following code: class Multithreading { int val; boolean value = false... { Multithreading th; Producer(Multithreading th) { this.th = th; new Thread
multithreading
multithreading  is multithreading is inbuilt in java? if yes then why we implement thread seperately
Advertisements
MultiThreading
MultiThreading  In MultiThreading....I'm using Hashmap ....Is there any deadlock occurs?   HashMap has synchronization issues in multithreading. Simultaneous access to hash map must be handled by the programmer
wap
wap  wap to count the number of object created for class using static member method   Hi Friend, Try the following code: class CountObject{ static int ob = 0; public CountObject() { ob = ob + 1; } public static int
What is WAP?
What is WAP?  What is WAP?   Hi, Check the tutorial: What is WAP? Thanks
multitasking and multithreading
multitasking and multithreading  what is the difference between multitasking and multithreading
string wap
string wap  WAP to convert stack trace in to a String . Write that Stack Trace in Error Log File along with the class name and Method Name that has thrown the error.in java language
What is Multithreading in Java?
What is Multithreading in Java?  What is Multithreading in Java? Can any one explain me the concept of What is Multithreading in Java? Thanks   Hi, The Multithreading is process of executing many programs
Describe synchronization in respect to multithreading.
Describe synchronization in respect to multithreading.  Hi, Describe synchronization in respect to multithreading. thanks,   Are you... the synchronization in respect to multithreading
Multithreading in Java
Multithreading in Java      ... a single thread. Lets us know about the concept of multithreading and learn... OS. Multithreading: Multithreading is a technique that allows
Multithreading in Java
Multithreading in Java     ... thread. Lets us know about the concept of multithreading and learn... by a single OS. Multithreading : Multithreading is a technique
java multithreading - Java Beginners
the following code: class Multithreading { int val; boolean value = false... Runnable { Multithreading th; Producer(Multithreading th) { this.th = th; new... { Multithreading th; Consumer(Multithreading th) { this.th = th; new Thread
Multithreading ? - Java Interview Questions
Multithreading ?   Hi Friends, I am new to java , am not clear with Multithreading. Multithread will cause deadlock. We can...; Hi friend, Multithreading is a technique that allows a program
WAP to find HCF
WAP to find HCF  Hi, can any one please share teh code to find the HCF of 2 or 3 numbers
Wap Application - MobileApplications
Wap Application  Hi, i need Wap application using Asp.net with c#. were user can download themes, games,wallpapers,songs etc from our application. Almost i create application but i dont know which dll i have to Use to sending
wap site - Development process
wap site  Please tell how to code to identify the mobile modal and manufacturer when any one hit my WAP site. I am using jsp + ejb. Please tell me which technology should i use to do this code. I have a java platform of web j2ee
Synchronization with Multithreading - Java Beginners
method. Then how can u achieve multithreading.   Hi friend
What is WAP? Detailed discussion of WAP API with examples.
WAP Tutorial Learn WAP quickly. Learn WAP in 60 minutes Wireless Application Protocol or WAP for short, allows
WAP in java to print the series 1*2*3
WAP in java to print the series 1*2*3  WAP in java to print the series 123
What is WAP? Wireless Application Protocol
; What is WAP?Wireless Application Protocol or WAP for short is simply a protocol... wireless networks. Thus WAP links Wireless Network
Multithreading in Java
Multithreading in java is running multiple threads sharing same address space... by the operating system. A thread never exists on its own. Multithreading allows..., multitasking can be carried out in two ways: Multiprocessing Multithreading
Java Multithreading
Java Multithreading       Multithreading allows two parts of the same program to run concurrently... at the same time.  In case of Multithreading, if more than one thread
WAP Toolkits Motorola - Mobile ADK 1.1 Nokia - WAP Toolkit
; WAP ToolkitsTo develop any WAP...;    List of WAP Toolkits and WAP Gateways 3G
Multithreading in Java
Multithreading in Java      ... a single thread. Lets us know about the concept of multithreading and learn... OS. Multithreading: Multithreading is a technique that allows
wap showing three threads working simulteniously upon single object.
wap showing three threads working simulteniously upon single object.  wap showing three threads working simulteniously upon single object
I really need a tutor for Java program that has to do with multithreading and gui!
I really need a tutor for Java program that has to do with multithreading and gui!  I am looking for a Tutor to help me with a Java program, specially GUI and multithreading. If you can tutor, please email me
How do servlets work? Instantiation, session variables and multithreading
How do servlets work? Instantiation, session variables and multithreading  How do servlets work? Instantiation, session variables and multithreading
Multithreading Java Tutorial for Beginners
Multithreading in Java means two or more parts of program run simultaneously. Every single part is called thread. Running them simultaneously saves time. Different threads run in simultaneous mode. Multithreading Java tutorials
Java Multithreading Example
Java Multithreading Example In this section we will discuss how we can do a different task using the different threads. In Java Multithreading we can create multiple threads to run different tasks. This example will demonstrate you
WAP to calculate addition of two distances in feets and inches using objects as functions arguments in java
WAP to calculate addition of two distances in feets and inches using objects as functions arguments in java  WAP to calculate addition of two distances in feets and inches using objects as functions arguments in java   
WAP to calculate addition of two distances in feets and inches using objects as functions arguments in java
WAP to calculate addition of two distances in feets and inches using objects as functions arguments in java  WAP to calculate addition of two distances in feets and inches using objects as functions arguments in java   
Advertisements
 

 

 

DMCA.com