Partheban Udayakumar wrote:Hi,
Does open streams affect the CPU usage and memory? In my project, I have Data IO Streams which are socket connected streams as
If I close these streams after using the socket connections too get closed. I am doubting that open streams cause CPU usage and memory. Am I correct? If now what causes high CPU usage and memory?
Everything you do in your
Java program will have some affect on the CPU usage and memory usage on your system. The various different stream objects take a non-zero amount of memory to construct, and whenever your program does something it will almost certainly involve the CPU at some point.
However if you're talking about idle streams (where you open them and then never send or receive any data) then I would wager that they have a negligible effect on CPU and memory usage. Then couple that with the fact that the operating system probably farms out a lot of the network IO processing to the network card then I doubt even in the general case that the sockets will have much impact on CPU and memory usage.
The real contribution to those resources will come from your code that uses the sockets. When you read data from a stream it will be placed into memory. When you process data for sending or after receiving it then it will use CPU usage. So if you use a stream to read a 1GB file into memory then you'll have used up a lot of memory, and if you process that file you will use some CPU etc.