JVM track any objection creation [duplicate] - java

This question already has answers here:
How to intercept object creation in Java lower than user class level
(2 answers)
Closed 6 years ago.
Many times I've seen some people tracked how the VM creates objects and how it performs optimization (eg: String concatenation). Unfortunately I can't find the correct command. Does anyone know?

The best tool for this kind f investigation is to use a profiler. I would start with Flight Recorder to record object allocations and CPU consumption and where this is happening.

Related

stop(getSelf()) vs stop(this.getSelf()) [duplicate]

This question already has answers here:
In Java, what is the difference between this.method() and method()?
(9 answers)
Closed 4 years ago.
I have been studying Akka Actors. I know the meaning of stop(ActorRef) which kills the running actor. But what is the difference between getSelf() and this.getSelf() while killing an actor? Thank You in advance!.
There's no difference between them, it's just that some people believe it enhances readability.
Readability is an important thing in programming but in this specific case, I personally believe they are just as readable with or without the this prefix.

Pinging many devices simultaneously as a nonblocking thread in Java [duplicate]

This question already has answers here:
Ping multiple servers in Java [duplicate]
(2 answers)
How to ping an IP address
(16 answers)
Closed 5 years ago.
I want to ping many machines to obtain information of their reachability. Time is critical here and I dont want to wait 1-2 seconds for every machine (assuming that there are hundreds of them). I tried this code snippet and turns out that the isReachable method is synchronous.
InetAddress.getByName(host).isReachable(timeout);
I need a way to make either that method (if possible) nonblocking or come up with another solution that will help cut down the waiting time.
Any help would be greatly appreciated. Thanks in advance.

how would i get the current size of the variable in java [duplicate]

This question already has answers here:
How to determine the size of an object in Java
(28 answers)
Closed 8 years ago.
Yes , this question is little bit vague and any serious programmer would laugh about it ! Although java does not tell about the sizes it assigns to the varibles ,i mean it can give more memory or less memory depending on the situation( that way it is abstracted !)i know that stuff! but what i am asking is ,is there any technique that i can know about the runtime variable size ? i want to find the addresses of the variables too ! This question does not want any answers like ,see java docs it does not provide those functionality you have asked , i want some kind of hack to do this kind of stuff!
Well, There is no such direct way to get accurate size consumed by each object in JVM. Although you can you use JCONSOLE or other similar monitoring tool to get footprints of the objects dynamically. Again, this is more towards monitoring and performance tuning.
Thanks, Anil

concept of multithreading in java [duplicate]

This question already has answers here:
How does Java handle multithreading?
(4 answers)
Closed 9 years ago.
While doing multi-threading programming in C we can assign threads to different cores of a processor and it gives us surety that the threads will be executed in different cores (i.e hyper-threading).But how exactly java does the above task--
Does it assign the threads to a single core and execute it in
time-stamp basis or assign to different cores..?
If it assign the above to different cores then how..?
By default, Java does not implement any form of Thread affinity. However, because it uses the underlying operating system's threads, it is possible to use native code to set the cpu affinity for a thread. One example of a project that does this is here: https://github.com/peter-lawrey/Java-Thread-Affinity

What's deadlock in programming? [duplicate]

This question already has answers here:
What is a deadlock?
(19 answers)
Closed 9 years ago.
What is deadlock in programming Object Oriented ?
I had knew deadlock in transaction of Database Systems. But in programming I'm not clear.
I want to know when deadlock occur and how to resolve it.
Thanks!
A deadlock is when you have two or more processes that are each waiting for the other to finish. When this happens, neither one can continue and the program essentially stalls.
There is a basic example here
http://docs.oracle.com/javase/tutorial/essential/concurrency/deadlock.html
well documented.
but, a deadlock occurs when you wait for a object to be freed but that condition is never achieved.

Categories

Resources