I want to know that in your opinion the best way to implement a program is to exchange two thread strings, Are providing each other
I could not get it to work, either with Java. NIO Pipe and java.oppdinputstream / java.opopedoptput.stream
Here's an example of code that I want to do:
Setting the main category, everything.
public static zero main (string [] args) {// TODO // Create two communication channels, and bind them MyThread t1 = New MyThread (channel1Reader, channel2Writer, 0); MyThreadT2 = New MyThread (Channel 2 Reader, Channel 1 Water, 1); T1.run (); T2.run (); } thread class:
public class expanded MyThread thread {Private? input stream; Private? OutputStream; Private boolean cantalk; Private Ent ID; Public maththread (? Inputstream, output stream, boolean is start, id) {this.inputstream = inputstream; This.outputstream = outputstream; This.canTalk = is starting; This.id = ID; } Public Zero Run () {While (true) {if (canTalk) {string s = getRandomWord (); // TODO // write to output stream in} // TODO // Wait until the string is received on the input string. String s2 = I have yet to login .fo ("thread" + id + "received word" + s2 + "''); cantalk = true; thread.Sleep (1000);}} Any ideas?
Thanks!
Pididine Output / OutputStream is Useful If you have a library in which to take the input / output stream, otherwise it is one of the least favorable ways to exchange data between threads.
However, the simplest to exchange data between threadsRica is to use an executable service. You can call for the qualified & lt; string & gt; service and & lt; String & gt;
Another way is to block several blocking queues & Lt; string & gt; But this does not save much and lacks functionality, which gives you an executor service.
With your example you have the problem that too Applying as a thread is simple to suggest that You see the functionality that is done by the best thread.
Comments
Post a Comment