As we know the java's garbage collector is a low priority thread. And in java we can create any thread with high priority. So is it possible to have our own customized garbage collector thread with variable priority (we can set depending on the level of memory man开发者_JS百科agement).
Did anybody tried that. If yes can you share some knowledge about how and its logic? Thanks
Java's garbage collector isn't "a low priority thread." For example, garbage collection often uses multiple threads in parallel. And, when memory runs low, garbage collection can preempt any application thread.
I recommend studying the Garbage Collection Tuning guide to determine the type of garbage collector best suited to an application, and how to adjust its parameters.
Garbage collection in Java has been finely tuned for years. It's possible but unlikely that you're doing something very special that has special needs in this area.
But what I think is more likely is that whatever problem you think you're having with the garbage collector are problems in your application. Some more guesses:
- You are unnecessarily creating and discarding a lot of objects.
- You have memory leaks.
- You have performance problems in your application.
- You have impossible performance expectations.
Yes you can, but it requires you to do some rather hard core JVM work, as you cannot do it from the running Java program. The easiest way to get started is probably using the Jikes RVM as it is written in Java (an IBM project gone Open Source).
http://jikesrvm.org/
Have fun, but expect an uphill battle :)
I believe you'd have to deploy your own JRE/JVM. There is no way to turn off the default garbage collection in Java.
Java 7 is going to use a completely new GC, so it should be possible to just swap them out.
精彩评论