Results 1 to 3 of 3
Thread: Exchanger Class
- 03-21-2014, 06:34 PM #1
Exchanger Class
Hy everybody, please have a look why this code doesn't show any output ... thanks in advance
Java Code:/* ---- Exchanger Class Demo ---*/ import java.util.concurrent.Exchanger; class MakeString implements Runnable{ Exchanger<String> exg; String str; public MakeString(Exchanger<String> exg){ this.exg = exg; str = new String(); new Thread(this).start(); } public void run(){ char c = 'A'; for(int i = 0; i < 3; i++){ for(int j = 0; i < 5; j++) str += c++; try{ str = exg.exchange(str); /* exchange with empty string */ }catch(InterruptedException IE){ System.err.println("Thread Interrupted"); } } } } class UseString implements Runnable{ Exchanger<String> exg; String str; public UseString(Exchanger<String> exg){ this.exg = exg; new Thread(this).start(); } public void run(){ try{ for(int i = 0; i < 3; i++){ str = exg.exchange(new String()); System.out.println("GOT: " + str); } }catch(InterruptedException ie){ System.err.println("Thread Interrupted"); } } } public class ExchangerApp{ public static void main(String[] args){ Exchanger<String> exg = new Exchanger<>(); new UseString(exg); new MakeString(exg); } }
- 03-21-2014, 06:44 PM #2
Re: Exchanger Class
why this code doesn't show any output
Try debugging the by adding some println() statements to print out the values of variables as the code executes so you can see what the computer sees when it executes and know why it is doing what it is doing when the code executes.If you don't understand my response, don't ignore it, ask a question.
- 03-28-2014, 06:12 PM #3
Similar Threads
-
Calculator: Buttons don't show up on Test JFrame class from JPanel class(w/ bg image)
By manibby93 in forum New To JavaReplies: 3Last Post: 12-08-2013, 09:28 PM -
Class example not compiling Runner class and Swimmer class
By Joshsmith in forum New To JavaReplies: 1Last Post: 12-13-2012, 03:06 AM -
could not find or load main class | cannot manually locate class file
By Holden Caulfield in forum New To JavaReplies: 1Last Post: 11-29-2012, 09:46 AM -
How to get a compatible class of a template class? Return type of method is AClass<E>
By SKuypers in forum Advanced JavaReplies: 0Last Post: 12-07-2011, 11:55 AM -
Eclipse Compile Error: Call validateValue(Class<T>, String, Object, Class<?>...)
By Tomshi in forum EclipseReplies: 0Last Post: 03-27-2011, 05:49 AM
Bookmarks