3

In my application (at my work), we maintain socket connection pool to handle the communication . There are a number of threads (number is large) which take an active connection from the pool, use it and close it. But the catch is that somewhere in between garbage collector is invoked to collect the references not in use.

Now, after the garbage collector is invoked I want to:

  1. suspend all the threads which participate in the communication(please note that my threads run together with the GC -> I mean scheduling makes it possible)
  2. release the socket connections from the thread (i.e.references to the socket connection) whose status may be somewhere in between or if that is practically not feasible then:
  3. How to delay the invocation of GC after all the threads using the resources have finished. further in this case it may be required to determine whether the relevant threads have finished their job.
4

1 回答 1

2

如果您关心 GC 何时运行,那么您的应用程序设计就会被破坏。

修复您的设计。


注意:虽然有关于垃圾收集器应该如何操作的规范,但 JVM 实现甚至不需要垃圾收集

于 2012-05-21T00:13:36.407 回答