| |

VerySource

 Forgot password?
 Register
Search
View: 584|Reply: 1

NIO gets performance issues, delays always appear ~~~~

[Copy link]

1

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-1-28 23:20:02
| Show all posts |Read mode
A communication program. One of my classes uses NIO to obtain data from the gateway and then combines the data. After processing, the global variable is passed to another class through a String. This class writes this string into NIO through NIO. Get the Channel, and the client gets the string variable from the Channel through NIO. However, a delay occurred about 8 minutes after this operation.
If I don't write the string variable to the client, there will be no delay ~~~~~~~~~~~~~~~
What's going on ~~~~~~~~~~~~

public void writeToChannel (SocketChannel channel, String message) throws IOException {
// System.out.println ("write");
int x = channel.socket (). getSendBufferSize ();
ByteBuffer buf = ByteBuffer.allocateDirect (x);
buf = ByteBuffer.wrap (message.getBytes ());
// ByteBuffer buf = ByteBuffer.wrap (message.getBytes ());
// int nbytes = channel.write (buf);
channel.write (buf);
buf.clear ();
channel.close ();
}
It is written into the Channel through this method. Is there anything wrong? ? ?
Reply

Use magic Report

0

Threads

39

Posts

23.00

Credits

Newbie

Rank: 1

Credits
23.00

 China

Post time: 2020-7-5 21:30:02
| Show all posts
channel.close();? Close every time you write? Isn't it a long connection?
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list