Home Answers Viewqa Java-Beginners wap for multithreading

 
 


neeraj
wap for multithreading
1 Answer(s)      2 years and 7 months ago
Posted in : Java Beginners

wap for multithreading

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 Pages:
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
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
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
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.... Multithreading : Multithreading is a technique that allows a program
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
Synchronization with Multithreading - Java Beginners
method. Then how can u achieve multithreading.   Hi friend
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
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
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 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      ... a single thread. Lets us know about the concept of multithreading and learn... OS. Multithreading: Multithreading is a technique that allows
WAP Toolkits Motorola - Mobile ADK 1.1 Nokia - WAP Toolkit
; WAP ToolkitsTo develop any WAP...;    List of WAP Toolkits and WAP Gateways 3G
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
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
Q, 12 WAP to calculate addition of two distances in feets and inches using objects as functions arguments in java
Q, 12 WAP to calculate addition of two distances in feets and inches using objects as functions arguments in java  Q, 12 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  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   
Writing your First WAP Application.
; As mentioned earlier WAP applications...) for WML is provided by WAP Forum and is available
Thread priority in java
Thread priority in java A thread is a part or entity of a  process that  is scheduled for execution. As we know java is a multithreading language which means JVM allow an application to have multiple thread running
Ques
Ques  wap to calculate Compound intrest wap to convert a string into lcase ucase concat length
java - Java Interview Questions
java  java's multithreading system is built upon_____class and________interface
WEBSERVICE USING APACHE AXIS- TUTORIAL-2 J2ME CLIENT FOR EJB & EJB-WEBSERVICE
with how to write WAP client for accessing ejb. In the same way, we are going
deteminant - Java Beginners
deteminant  wap to find the determinant of any order matrix
java program
java program  wap to show concept of class in java
kaprekar
kaprekar   wap to input a number . check whether the no. is kaprekar
kaprekar
kaprekar   wap to input a number . check whether the no. is kaprekar
kaprekar
kaprekar   wap to input a number . check whether the no. is kaprekar
java programming:generating series
java programming:generating series  WAP to print series: | + || + ||| + |||| + .......... n terms
Java multi-threading
Java multi-threading  How does multithreading take place on a computer with a single CPU
core
core  where an multythread using   Please go through the following link: Java Multithreading
write following program
on thread synchronization with examples Q4 WAP that asks the user to input... is a package? how is it useful? Demonstrate with example? Q8 WAP that creates 2...-cycle? Q10 WAP that asks the user to input 2 string. If the strings are same
functions - Java Beginners
functions  WAP a program to print the value of 'z'- z=(sin(2x)+cos(2y)+sin(2y)-cos(2x
java
java  WAP a program to fcalculate commisson earned by a travel agency on the following tour pacages trip to goa-15% trip to mumbai-25
Java Loop 2 - Java Beginners
Java Loop 2  WAP to print d following patter wid d help of ne loop possible
java
java   wap to find largest number of list of no. entered through keyboard