52

I'm writing a Java application that runs on Linux (using Sun's JDK). It keeps creating /tmp/hsperfdata_username directories, which I would like to prevent. Is there any way to stop java from creating these files?

c-had
  • 1,380
  • 1
  • 9
  • 18

8 Answers8

40

Try JVM option -XX:-UsePerfData

more info

The following might be helpful that is from link https://docs.oracle.com/javase/8/docs/technotes/tools/unix/java.html

-XX:+UsePerfData

    Enables the perfdata feature. This option is enabled by default
    to allow JVM monitoring and performance testing. Disabling it 
    suppresses the creation of the hsperfdata_userid directories. 
    To disable the perfdata feature, specify -XX:-UsePerfData.
caot
  • 3,066
  • 35
  • 37
Kyle Renfro
  • 1,238
  • 2
  • 12
  • 18
  • 6
    Just to point out that using either of -XX:+PerfDisableSharedMem or -XX:-UsePerfData will not allow JConsole, VisualVM and similar tools to connect to the JVM unless you activate JMX. – Eldelshell Jan 09 '12 at 09:48
  • The "more info" link has been fixed. – Kyle Renfro Apr 17 '13 at 12:49
36

Use the JVM option -XX:-UsePerfData.

This will not have a negative effect on performance, as some other answers say.

By default jvmstat instrumentation is turned on in the HotSpot JVM. The JVM option -XX:-UsePerfData turns it off. If anything, I would speculate, turning off the instrumentation would improve performance (a trivial amount).

So the downside of turning off jvmstat instrumentation is that you lose the performance monitoring information.

jvmstat is described here http://java.sun.com/performance/jvmstat/

Here's a thread with someone who is worried that by turning on jvmstat - with the option -XX:+UsePerfData - will hurt performance. http://www.theserverside.com/discussions/thread.tss?thread_id=33833
(It probably won't since jvmstat is designed to be "'always on', yet has negligible performance impact".)

Jon Stafford
  • 1,334
  • 1
  • 12
  • 16
  • 2
    Also see this blog post from a softare engineer at Twitter: http://www.evanjones.ca/jvm-mmap-pause.html There he describes a positive effect on garbage collector pause times. – Peter Mar 31 '15 at 10:52
4

Rather than switching it off, change the java.io.tmpdir location. Add -Djava.io.tmpdir=/mydir/somewhere/else/ to your Java startup command and then the file will be somewhere that you control.


Note a comment by @simonc: this only works in a few versions of the JVM and is no longer supported. See http://bugs.sun.com/view_bug.do?bug_id=6447182, http://bugs.sun.com/view_bug.do?bug_id=6938627, http://bugs.sun.com/view_bug.do?bug_id=7009828 for more information.

eis
  • 51,991
  • 13
  • 150
  • 199
Mack
  • 109
  • 3
  • 5
    I know this is an old question, but for the Google searchers: this only works in a few versions of the JVM and is no longer supported. See: http://bugs.sun.com/view_bug.do?bug_id=6447182, http://bugs.sun.com/view_bug.do?bug_id=6938627, http://bugs.sun.com/view_bug.do?bug_id=7009828. – SimonC Feb 22 '12 at 03:56
2

There is also "-XX:+PerfDisableSharedMem" option (recommended by Sun) which should cause less performance issues than use of "-XX:-UsePerfData" option.

Jérôme Verstrynge
  • 57,710
  • 92
  • 283
  • 453
Zweiberg
  • 21
  • 1
2

As an addendum to Mack's reply (answered Mar 25 '11 at 17:12), the option java.tmp.dir looks no longer available since Java 8. See the info at: https://bugs.java.com/view_bug.do?bug_id=8189674

So disabling the option using -XX:-UsePerfData seems the only option not to have hsperfdata_* files.

2

EDIT: Cleanup info and summarize

Summary:

  • Its a feature, not a bug
  • It can be turned of with -XX:-UsePerfData which might hurt performance

Relevant info:

svrist
  • 7,042
  • 7
  • 44
  • 67
  • The bottom of that page outlines a solution, that does indeed work. – rcreswick Sep 16 '08 at 20:20
  • Down votes are not hostile actions. They just reflect the percieved accuracy of your answer. Your original answer indicated it could not be solved ("Looks like you cant"). That just was not true. – Stu Thompson Sep 16 '08 at 21:02
1

From svrist's link:

The first item in http://java.sun.com/performance/jvmstat/faq.html mentions an option which you can turn off to disable the whole suite of features: -XX:-UsePerfData.

Stu Thompson
  • 38,370
  • 19
  • 110
  • 156
1

According to the filed bug report there is a work-around:

This undocumented option will disable the perfdata feature:
-XX:-UsePerfData

It's worth mentioning that it is a feature though, not a bug. The above work-around just disables the feature.

Community
  • 1
  • 1
SCdF
  • 57,260
  • 24
  • 77
  • 113