English 中文(简体)
我如何发现哪些物体在 Java有档案?
原标题:How can I find out which object has a file open in Java?

我需要找到,在我的 Java口中标有。 这是为了进行分解,因此欢迎各种工具或公用事业。

如果发现<>标的<>/>号太具体,<>/strong>也将非常有益。

最佳回答
问题回答

下面是Windows和IntelliJ,尽管在其他操作系统和IDEs中可能相似。

此外,根据JDK内部情况,为JDK11撰写了以下文字:


  1. Find out the handle of the file. For this you can use the Windows Sysinternals Handle tool (see also this Server Fault question):
    .handle64.exe -p java
    
  2. In the output search for the relevant file, e.g.:
    D7C: File          C:UsersSomeonemyfile.txt
    
    (Note: Most terminals provide a search function, for cmd.exe it is Ctrl + F; for Windows Terminal it is Ctrl + + F.)
    The value before the colon is important (in this example D7C), note it down.
  3. In IntelliJ pause execution with the debugger.
  4. Open the Memory tab
  5. Search for java.io.FileDescriptor
  6. Right-click the result and select "Show Instances"
  7. As condition enter handle == 0xhandle, with handle being the value you noted down in step 2 (in this example handle == 0xD7C).
    (Note: Under Unix you might have to compare fd == instead.)
    ➔ You should see a single result
  8. Right-click the result and select "Show Referring Objects..."
  9. On the results you can then continue selecting "Show Referring Objects..." until you found the relevant result (the reference in FileCleanable can most likely be ignored)

This won t always answer which caller forgot to close the file, but it might give a hint. You can then for example set further breakpoints in the relevant classes to find out who opened the file.

Use AspectJ and intercept calls to various flavors of opening file streams. Use an around aspect. Note this can only tell you which object opens the stream, but obviously the object can pass around references to the stream, so ...





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...