Home Tutorialhelp Comment Interthread code need some correction

 
 

Comment

Avneesh Saini
Interthread code need some correction,
August 8, 2008 at 12:53 PM

Interthread Class code

it needes slight modification to get desired output:

class Shared {

int num=0;
boolean value = false;

synchronized int get() {
if (value==false)
try {
wait();
}
catch (InterruptedException e) {
System.out.println("InterruptedException caught");
}
System.out.println("consume: " + num);
value=false;
notify();
return num;
}

synchronized void put(int num) {
if (value==true)
try {
wait();
}
catch (InterruptedException e) {
System.out.println("InterruptedException caught");
}
this.num=num;
System.out.println("Produce: " + num);
value=true;
notify();
}
}


View All Comments | View Tutorial
Advertisement
Related Tutorial and Articles
Programming Tutorials

Interthread Communication
; This technique is known as Interthread communication which is implemented by some... to give up the monitor and go to sleep until some other thread enters...:\nisha>javac InterThread.java C:\nisha>java InterThread 

General

Interthread Communication in Java
Interthread Communication in Java As you know about producer-consumer problem... below some function helpful in interthread communication : Methods... the monitor and go to sleep until some other thread enters the same 

Java Beginners

MISTAKES CORRECTION - Java Beginners
, P.Ravichristy  I used ur code which... java.awt.Image; public class AppletSleep1 extends Applet implements Runnable { Thread thread = null; final static int width = 400; final static int height = 300 

General

Interthread communication
; This technique is known as Interthread communication which is implemented by some... to give up the monitor and go to sleep until some other thread enters... InterThread.java C:\nisha>java InterThread Produce: 1 

Java Beginners

MISTAKES CORRECTION - Java Beginners
Java Sleep programe was received through your favor. But when I compiled... Runnable { Thread thread = null; final static int width = 400; final static... visits the page, create a new thread if(thread == null){ thread = new Thread 

Java Beginners

Thread
some code like this: class A extends Thread { public void run...Thread  will this code work..? class A extends Thread { public... attaching class object to thread..?   There are some compilation errors 

Java Beginners

Java Question Anyone need some HELP !!
Java Question Anyone need some HELP !!  Create a file that contains... of the two files. Note: For the above code, you need POI api. import... and poi-scratchpad-3.2-FINAL-20081019.jar files into the following path: \Java 

Java Beginners

Thread
Thread  why we need threads? why we need Multithreads? with code and real time example 

Java Beginners

Thread
;Java throw and throws Whenever we want to force an exception then we use throw... a possible exception then we use throws keyword. Point to note here is that the Java compiler very well knows about the exceptions thrown by some methods so it insists 

Java Beginners

Need some help urgently
Need some help urgently  Can someone please help me with this below question. I need to write a class for this. If you roll Y standard six-sided dice... number of possible combinations.   The actual question got some error. Its 

Spring Framework Questions

Need the some guidence - Spring
Need the some guidence  Hi, MY name is pavan iam having mini projects in MCA these are the details reg projects below 1.project name:identical... give me detail and source code where you are confuse. Thanks 

Java Beginners

Need an example of basic code.
Need an example of basic code.   Im working on an art project that I want to use some code in, and I am proficient in python but that looks fairly simple so I was hoping java would look more impressive. So I just need a visual 

Java Beginners

Need an example of basic code.
Need an example of basic code.   Im working on an art project that I want to use some code in, and I am proficient in python but that looks fairly simple so I was hoping java would look more impressive. So I just need a visual 

Java Beginners

Need an example of basic code.
Need an example of basic code.   Im working on an art project that I want to use some code in, and I am proficient in python but that looks fairly simple so I was hoping java would look more impressive. So I just need a visual 

Java-Tutorials

Java Thread
into the running state. Waiting : Sometimes it is need to put some 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 

Java Beginners

need java code - Java Beginners
need java code  i want a program for an algorithm in java which is it has some transactions T1=ABCE T2=CDE T3=DE T4=CDEG T5=BG T6... result . For this algorithm i need a program can any help me 

Java Beginners

JAVA THREAD - Java Beginners
JAVA THREAD  hii i wrote a pgm to print the numbers from 0 to 9 in 2 threads. but it couldn't work pls help me int it. the code is given below...); } public void fgh(int i,int p) { int sum; new Thread(public void run 

Java Beginners

need of code
need of code  howto convert greyscale image to binary image in java 

Development process Questions

Need the Following MobileApplication Related Code
Need the Following MobileApplication Related Code  Hi, I need java...: and one Daemon Thread class need's to run while doing the above operations and if you can provide code in switch cases,I feel more happy. Please reply me ASAP 

Java Beginners

Thread - Java Beginners
Thread  Can i ask a thread method that will input two names using... sending running code. import javax.swing.*; import java.awt.event.*; import... = JOptionPane.showInputDialog(null, "Enter some text : ", "Roseindia.net", 1 

Java-Tutorials

Overview of Thread
Programming language,  thread is a sequential path of code execution... when the main() method complete its execution. The main thread creates some other... with this program. Thread A thread is a lightweight process which exist within 

Java Interview Questions

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 

Java Beginners

PLZ Need some help JAVA...HELP !!
PLZ Need some help JAVA...HELP !!  Create a class names Purchase Each purchase contains an invoice number, amount of sale and amount of sales tax. Include set methods for the invoice number and sale amount. Within the set 

Java-Tutorials

Java :Thread dumpStack
Java :Thread dumpStack In this tutorial you will learn about Java Thread dumpStack . Thread dumpStack : JVM gives the concept of Thread Dump which..., some of them going to die or in waiting stage. Functionality of Thread stack 

Java Beginners

java thread problem - Java Beginners
java thread problem  Hi Friends, My problem is related with java.util.concurrent.ThreadPoolExecutor I have a thread pool which using LinkedBlockingQueue to send some runnable object . Samples Code : ThreadPoolExecutor 

Java-Tutorials

Java : Runnable Thread
Java : Runnable Thread In this tutorial we are describing Runnable Thread with example. Runnable Thread : Runnable thread is an easy way to create a thread by implementing the Runnable interface. You need to implement a single 

Java Beginners

CREATE AND WRITE FILE THREAD JAVA
CREATE AND WRITE FILE THREAD JAVA  Hi guys I was wondering how can I make this program in java with threads. I need to create a file and write...=5120 kb** I really need some help guys 

Java Beginners

really need help on how to write this program plz some 1 help out. - Java Beginners
really need help on how to write this program plz some 1 help out.  i am confused here on what to write can some 1 help out here i dont quite understand how to code it so can some 1 help out. Part II Write, compile and execute 

Java-Tutorials

Thread Synchronization in Java
Thread Synchronization in Java Sometimes, when two or more threads need shared resource, they need a proper mechanism to ensure that the resource will be used by only one thread at a time. The mechanism we use to achieve this is known 

Java-Tutorials

What Is Thread In Java?
, it is defined. Every Java program is run as a thread, thread is a sequential path of code...What Is Thread In Java? In this section we will read about thread in Java... execution and the description of the example. Before, defining a Thread in Java 

Java Beginners

need code - Java Beginners
need code   i want to take the html coding. if user give a input html.... (view -> source) . how it is possible in java.  Hi Friend, Here we are sending you a sample code which will be helpful to you. import java.io. 

General

Java Exception Thread
to Overcome this Thread Exception in Java Program In the preceding code, we... Java Exception Thread     ...( java.lang.thread) 2)Implement Runnable interface( java .lang. thread) Understand 

General

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 

Java Beginners

i need some help in understanding the following codes.thanks..
i need some help in understanding the following codes.thanks..  this code is to perform LocalColorHistogram.But i can't understand it public Vector<Double> getFeatureVector(int[] inImg, int height, int width, int[] maskImg 

General

Get Current Thread
. Many thread runs concurrently with a program. Some threads are Multithread.... The thread in java is created and controlled by the java.lang.Threadclass. Two... to describe you a code that helps you in understanding Get Current Thread. For this we 

Java Beginners

code need - Java Beginners
code need  hi i want to code doing for this. If i have enter the text file in my java project. example input is 1,2,3,4,5(it is in input text file...)  Hi Friend, Try the following code. We hope this will help you 

Java Beginners

Thread
Thread  Explain two ways of creating thread in java. Explain at three methods of thread class.   Java Create Thread There are two main ways of creating a thread. The first is to extend the Thread class and the second 

Programming Tutorials

Some Notes on Java Programming Environments
Appendix 2: Some Notes on Java Programming Environments ANYONE WHO...-line environments. All programming environments for Java require some text..., but you will need them if you are going to be serious about Java programming 

JUNIT Questions

Need of JUnit
Need of JUnit  Hi sir, What makes JUnit better than other testing tools for Java Unit testing?   Hi friend.. It is better to know pros & cons of technology, you are going to learn. So here are some key 

Core Java

Thread Life Cycle Example in java
Thread Life Cycle Example in java In this section we will read about the life cycle example of Thread in Java. Life cycle of Thread explains you the various stages of Thread in Java. These states are New State, Runnable State, Running 

Java Beginners

Demon thread
Demon thread  What is demon thread? why we need Demon thread?  ... there are daemon thread by killing them abruptly.Any thread can be a daemon thread. For more information, visit the following link: http://www.roseindia.net/java 

Java Beginners

Thread
Thread  What is multi-threading? Explain different states of a thread.   Java Multithreading Multithreading is a technique that allows... processor system. States of Thread: New state ? After the creations of Thread 

Java-Tutorials

Java Thread HoldsLock
Java Thread HoldsLock In this tutorial, you will learn how to lock a thread with example in Java. Thread HoldsLock  : It is easy to use synchronized code for locking but there is some limitation too 

Java Beginners

need java code - Java Beginners
need java code  I want java code for connect to bit.ly and our link is converted into shorten link and give me response. as a converted link 

Java Beginners

Thread
Thread  Write a Java program to create three theads. Each thread should produce the sum of 1 to 10, 11 to 20 and 21to 30 respectively. Main thread....   Java Thread Example class ThreadExample{ static int 

Java Beginners

Thread
Thread   there are two threads running at a time.. when am updating a values in database. both thread halt and stop for moment till it get updated into database... so i dnt want thread to get halts for tht moment of period. whats 

Java Beginners

adding some value to new column
adding some value to new column   how to update a column having some value into new column that also have some value i need to add this two value in java using result set we can get all the column data but how to add these value 

Java Beginners

java - need code - Java Beginners
java - need code  i am java developer. i want to remove file from one folder and same file is paste another folder. i need this code. (java)  hi, I am sending you the code which moves the file from one folder 

Java Beginners

need code for file browser
need code for file browser  hi, i need to write a code to browse the file in my computer using Jsp or java.. what is the code for file browser?   JSP Code for browsing: 1)page.jsp: <%@ page language="java" %> 

General

Inter-Thread Communication
thread to give up the monitor and go to sleep until some other thread...:\nisha>javac InterThread.java C:\nisha>java InterThread... Inter-Thread Communication      

Java Beginners

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 example code if possible. Thanks   Hello, Daemon thred are those 

Java Beginners

need help. - Java Beginners
output all the uppercase letters  can some one tell me how to output all the uppercase letters. Thanks in advance!!  Here, is the output... program code and get to the output in uppercase letter.amar 

JDBC Questions

Need Java Source Code - JDBC
Need Java Source Code  I have a textfield for EmployeeId in which the Id, for eg: "E001" has to be generated automatically when ever i click... be implemented.  Hi friend, Please send me code because your posted 

General

Java Thread
Java Thread       A java... sequential flow of control within a program. Programmer may use java thread mechanism...;thread is a sequential path of code execution within a program. Each thread has 

Java Beginners

thread class - Java Beginners
the following code: class Incrementor extends Thread{ int cnt1 = 0; boolean...thread class  Create 2 Thread classes.One Thread is Incrementor... value of cnt1 by 1 each time. The other thread is Decrementor which has variable 

Swing AWT

Need source code - Swing AWT
Need source code  Hai, I need a idea and code for developing the project "Face Recognition" with the backend as My-sql... send some more information. Thanks 

Java-Tutorials

Thread Deadlocks - Java Tutorials
Thread Deadlock Detection in Java Thread deadlock relates to the multitasking... is possible. In other words, a situation where a thread is waiting for an object lock that holds by second thread, and this second thread is waiting for an object 

Java Beginners

thread program for calculator implementation
thread program for calculator implementation  Hi i'm prem i need calculator progrm in java that are implemented by Thread interface.....pls strong text 

Java Interview Questions

Difference between Timer and Thread?
Difference between Timer and Thread?  Can anyone tell me about the difference between Timer and Thread, Why we need to have Timer in case we have Thread implimentation startegy in Java 

Development process Questions

need a Sample code - Development process
need a Sample code  i want run the python script in java code by using Runtime class and output should be formed like XML format.please help me. Advanced Thanks, Krishna 

Java Beginners

Thread and Process - Java Beginners
, threads have their own stack space. This is thread code, public class...Thread and Process  Dear Deepak Sir, What is the diffrence between Thread and Process.Give an example with explanation. Thnaks & Regards 

Development process Questions

Need to develop Java Program - Development process
Need to develop Java Program  Write a multi-threaded Java program to print all numbers below 100,000 that are both prime and fibonacci number (some examples are 2, 3, 5, 13, etc.). Design a thread that generates prime numbers 

Java-Tutorials

Java :Thread Methods
Java :Thread Methods This section explains methods of Thread class. Thread Methods : Thread class provides many method to handle different thread... and allow other threads the temporal executing thread object. Some other methods 

Java Beginners

i need a java code for finding typemismatch in an editor.
i need a java code for finding typemismatch in an editor.  hi im sriram, i need a java code in such a way that typemismatch code is embedded with the simple java editor. the sample output is shown below !alt text 

Java Beginners

Need to have a Java Code - Java Beginners
Need to have a Java Code  Dear Friend, Can we run a unix command like "df -tg" in a remote linux system through FTP server using Java Program? Kindly give me the solution for the above query. Thanks & Regards 

Java Beginners

Inter Thread Communication
: http://www.roseindia.net/java/thread/InterthreadCommunication.shtml http...Inter Thread Communication  what is inter thread communication?   hi friend, Inter thread communication is a process of communication 

Java Beginners

Need a Code to calculate hair density in java
Need a Code to calculate hair density in java  Hello, Would you please give me a code to calculate the hair density on scalp from image in java 

Swing AWT

Need source code - Swing AWT
Need source code  Hai, In java swing, How can upload and retrieve the images from the mysql database?   Hi Friend, To upload and insert image in database, try the following code: import java.sql.*; import 

Java Beginners

need java code for <company:loc="bang">
need java code for   hi i want to write code like , i used setAttribute method for this. but its showing ERROR: 'Namespace for prefix 'company... me to write this syntax in java 

Java-Tutorials

Java Thread Interrupted
Java Thread Interrupted In this tutorial, you will learn how to interrupt a thread with example in Java. Thread Interrupt : Java thread facilitate you to interrupt any thread. Interrupting a thread means to stop the running thread 

Java-Tutorials

Java Thread setName() Example
Java Thread setName() Example In this section we are going to describe setName() method with example in java thread. Thread setName() :  Suppose,  you want to change name of your thread so for that java thread provides 

Hibernate Questions

Need for hibernate - Hibernate
Need for hibernate  Can anyone say why should we go for hibernate... oriented concept like java. It has better compatibility with java than sql. In Jdbc we have to mannualy handle exception We need to open/cose the connection 

Struts Questions

Single thread model - Struts
Single thread model  Hi Friedns , thank u in advance 1)I need sample code to find and remove duplicates in arraylist and hashmap. 2) In struts, ow to implement singlthread model and threadsafe 

Development process Questions

Java: Some problems in given condition
Java: Some problems in given condition   SIR, I want to get.... Then one alert should b printed in application using Java. If(att.getdata1()==0||att.getdata2()==0) If I use this code in Java.I am facing NullPointerException 

General

Java Thread Priority
Java Threads run with some priority There are Three types of Java Thread...() method. Java Thread Priority Example public class priority implements...++) System.out.println(x + " This is thread " + Thread.currentThread 

Java-Tutorials

Thread Creation
; In Java, an object of the Thread class can represent a thread. Thread...( ) method in the subclass from the Thread class to define the code executed... RunThread.java C:\j2se6\thread>java RunThread Thread 

Java-Tutorials

Java Current Thread
Java Current Thread In this tutorial, we are using Thread.currentThread() method to find the current thread name. Thread.currentThread() : Thread... method so that there is no need to call a reference to a Thread object 

Java Beginners

sleep method in thread java program
sleep method in thread java program  How can we use sleep method in thread ?   public class test { public static void main(String... some interval to the sleep method .After that interval thread will awake 

Development process Questions

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-Tutorials

Thread Constructors
Thread Constructors       Several constructors are available for creating new Thread instances.    Thread() Thread(String)   Thread(Runnable) Thread 

Java Beginners

need code
need code  Create Vehicle having following attributes: Vehicle No., Model, Manufacturer and Color. Create truck which has the following additional... is the required code: import java.util.*; class Vehicle { int 

Java Beginners

need code
need code  Create Vehicle having following attributes: Vehicle No., Model, Manufacturer and Color. Create truck which has the following additional... is the required code: import java.util.*; class Vehicle { int 

Java Beginners

need code
need code  Create Vehicle having following attributes: Vehicle No., Model, Manufacturer and Color. Create truck which has the following additional... is the required code: import java.util.*; class Vehicle { int 

Java Beginners

java Thread
java Thread  what is purpose of Thread 

Java Beginners

Thread in java
Thread in java  which method will defined in thread class 

Java-Tutorials

Java Thread : run() method
Java Thread : run() method In this section we are going to describe run() method with example in java thread. Thread run() : All the execution code... and the classes which intend to the execute their code. For using this method 

Java Interview Questions

thread related - Java Interview Questions
thread related  Hi, Plz tell me how two thread will communicate with each other. plz tell me with code. Thanks Narendra   Hi friend...() , notifyAl() methods. wait() method tells the thread to wait until another 

Java Interview Questions

Java thread
Java thread  How can a dead thread be restarted?  A dead thread cannot be restarted 

Java Interview Questions

Java thread
Java thread  What are the high-level thread states 

Java Interview Questions

Java thread
Java thread  What's the difference between a thread's start() and run() methods 

Java Interview Questions

Java thread
Java thread  What is the difference between process and thread 

Java Interview Questions

Java thread
Java thread  What invokes a thread's run() method 

Java Interview Questions

Java thread
Java thread  What are the ways in which you can instantiate a thread 

JSP Servlet Questions

i need the source code to generate id in jsp
i need the source code to generate id in jsp  hai,i need the source code for generate id...which is i need to generate the new id from the maximum... of generate ids each should have some range...plz give the source code in jsp with ms 

Date Calendar

code
code   hi I need help in creating a java code that reminds user on a particular date about their festival. i have no clue of how to do it.. am looking forward to seek help from you 

Core Java

Thread priority in java
Thread priority in java A thread is a part or entity of a  process... concurrently. In java each and every thread has priority , priority means which.... Thread class defines some priority constant as follows: MIN_PRIORITY = 1 NORM 

Swing AWT

in my project, i have to add scrollbars to a panel,. i need some example on it,how to doit.
in my project, i have to add scrollbars to a panel,. i need some example... need some example on it,how to doit. Thanks In Advance   Please visit the following links: http://www.roseindia.net/java/example/java/swing/use 

Java Beginners

Exception in thread "main" java.lang.ClassCastException
Exception in thread "main" java.lang.ClassCastException  I am trying to connect the database. I am stuck with this exception that is getting thrown. Anyone help me please. Java Code: import java.sql.; import org.postgis. 

JDBC Questions

Exception in thread "main" java.lang.ClassCastException
Exception in thread "main" java.lang.ClassCastException  I am trying to connect the database. I am stuck with this exception that is getting thrown. Anyone help me please. Java Code: import java.sql.*; import org.postgis. 

General

Java Thread In Applet
Java Thread Applet is a java class that runs inside the internet browser. It is used to make the gui application, network application in java Thread is used in applet to make the multithread application Example of Java Thread 

Advertisements Advertisements
 

 

 

DMCA.com