For Example
URL yahoo = new URL("http://www.gmail.com/");
So I need to Find the Total internet usage for this request using java..
For Example
URL yahoo = new URL("http://www.gmail.com/");
So I need to Find the Total internet usage for this request using java..
For starters, that statement doesn't generate a "request" and doesn't generate any internet traffic. It is just creating a URL
object.
If you were to fetch the content; e.g. like this
Object obj = new URL("http://www.gmail.com/")
.openConnection(). getContent();
then you would generate internet traffic. However, there is no easy way to measure how much traffic is generated from within a Java application.
I guess you could do some clever things in a custom "URLStreamHandler" to measure the number of bytes read and written at the socket stream level. But that doesn't tell you "total internet usage"; i.e. how many packets were read and written and how big they were. And it doesn't include the network traffic (potentially) generated by the DNS lookup.
If you want to measure real ("total") network traffic accurately, you are better of doing it at the OS level, or at the network level.