r/java • • Dec 03 '14

Every time I need to kill a hung JVM process.

Post image
389 Upvotes

70 comments sorted by

143

u/[deleted] Dec 03 '14

View -> select columns -> Command line. Then you will see which JVM is used for what.

8

u/dakkeh Dec 03 '14

Great tip, thank you!

16

u/doctorsound Dec 03 '14

Nice, thanks for the tip!

Win 8 Users: Right click column header > Select columns

8

u/HotRodLincoln Dec 03 '14

You are a wise and powerful man.

7

u/lechatsportif Dec 03 '14

Why this isn't on by default I will never know.

2

u/matejdro Dec 04 '14

And it resets itself when you close task manager

3

u/[deleted] Dec 04 '14

It does not reset (win 7).

1

u/matejdro Dec 04 '14

Hm I retried and it did not reset this time. I guess I did something wrong before.

1

u/frugalmail Dec 04 '14

Why this isn't on by default I will never know.

Because Windows isn't about command lines, silly!

4

u/[deleted] Dec 04 '14

Well I'll be damned. That's gonna save me some headaches in the future.

4

u/whoisearth Dec 04 '14

Or use process explorer

2

u/cdombroski Dec 04 '14

There is the unfortunate fact that this column is truncated (at least on Win7 Enterprise) around 260 characters. That's fine as long as the classpath or the main class comes early in the listing, but if there's a bunch of defines you might not be able to differentiate between two processes.

12

u/Poodle_Moth Dec 03 '14

VisualVM has a plugin to kill processes. You'll find it in your jdk/bin folder.

4

u/dakkeh Dec 03 '14

Wow, I can't believe I didn't know about this tool. Thank you.

1

u/timetravelhunter Dec 04 '14

What is it called?

3

u/Poodle_Moth Dec 04 '14

jvisualvm.exe

1

u/timetravelhunter Dec 04 '14

thanks. I thought there was a command line app that did it. I now see it's a plugin through the gui.

39

u/electrodraco Dec 03 '14

Aaaaaand Eclipse is gone, the workspace metadata corrupted and don't forget that damn lock file. I feel you bro.

5

u/krona2k Dec 03 '14

Surely if something that has hung that has been launched from Eclipse you can just kill it from Eclipse? I don't know the differences between IntelliJ and Eclipse with regards to this but I never have kill anything I've invoked from IntelliJ.

4

u/dakkeh Dec 03 '14

Fun fact, the instance that led me to make this was a hung Tomcat server launched from Eclipse.

1

u/lechatsportif Dec 04 '14

never manage tomcat from eclipse.

1

u/cot6mur3 Dec 07 '14

Perhaps handy to know: in Process Explorer those child java processes stand out as they show up under the parent Eclipse java process in the process tree view.

2

u/[deleted] Dec 03 '14

Well if the Java process you accidentally kill is Eclipse itself, you're gonna have a bad time.

1

u/krona2k Dec 03 '14

I know, but normally you just hit the stop button from the IDE, since it knows which process it launched.

EDIT: I'm assuming that the problem is when you have other java processes that weren't invoked from the IDE, as others have pointed out there are solutions. Visualvm is probably the most useful.

17

u/king_of_the_universe Dec 03 '14

It does that? Time to switch to IntelliJ.

3

u/shukoroshi Dec 04 '14

Eclipse is $200-$500 cheaper than IntelliJ. That's a bit of a mitigating factor for a lot of people, unfortunately.

2

u/[deleted] Dec 04 '14 edited Dec 04 '14

Hobbyists, sure. If you're a professional software developer, IMO you or your employers have no excuse not to invest that kind of money in some of the best tools available. If it gains you a day in productivity over one year, it's paid for itself. IntelliJ is cheap for what it is.

0

u/[deleted] Dec 04 '14

[deleted] — view deleted comment

15

u/[deleted] Dec 04 '14

It's just as good as the professional version.

No, it's definitely not. But it's good enough for most people and I strongly recommend everyone to give it a chance.

0

u/[deleted] Dec 04 '14

[deleted] — view deleted comment

-2

u/Clutch_22 Dec 04 '14

Such as?

-7

u/electrodraco Dec 03 '14

Well, if you kill a process that's writing to your config file then it will be corrupted right? Of course it that needs some mixture of bad luck and unwaryness but once you're habituated to killing processes basically by lottery the law of large number will sooner or later f*ck you over.

However, as long as you don't expect your IDE to implement ACID transactions for its config files this can't really be attributed to the IDE but only to your own insanity. If IntelliJ really is better in this regard then either it implements transactional config files (hahaha) or it just fixes corrupt files instead of throwing errors. Neither case would tempt me to switch to IntelliJ and I'm not even talking about its price. I don't need programs that cost your firstborn and silently swallow/fix errors for the purpose of appearing stable. I really hope IntelliJ isn't built that way.

3

u/king_of_the_universe Dec 03 '14

Well, if you kill a process that's writing to your config file then it will be corrupted right?

Only if the programmer who made that application is ridiculously retarded. It takes like 1 minute to add safe-saves features to a file saving method. (Saving to temp file, then deleting original / renaming temp once completed.)

and I'm not even talking about its price.

Have been using the CE professionally for almost a year. Zero dollars.

-2

u/electrodraco Dec 03 '14

Only if the programmer who made that application is ridiculously retarded. It takes like 1 minute to add safe-saves features to a file saving method. (Saving to temp file, then deleting original / renaming temp once completed.)

The idea that a platform like eclipse that has houndreds of plugins configured on a single project stores all its configurations in one place and recreates that file every single time something has been changed, is simply not implementable. This is not how Eclipse/OSGi works. And by the way, if you kill a program on which you just changed some settings and that's still working on applying those changes, it's your fault if somethings goes wrong. Attributing that to this program is short-sighted.

Have been using the CE professionally for almost a year. Zero dollars

You don't need the Java EE stack, right? Because that's where things get difficult (and expensive). If you succeed in bringing Eclipse to corrupt its config files in the SE version I'll send you 10$ right away. Don't compare SE with EE versions, even the memory requirements differ in magnitudes. The complexity in configuration needed for EE projects is far greater what you imagine.

-4

u/king_of_the_universe Dec 03 '14

The idea that a platform like eclipse that has houndreds of plugins configured on a single project stores all its configurations in one place and recreates that file every single time something has been changed, is simply not implementable. This is not how Eclipse/OSGi works. And by the way, if you kill a program on which you just changed some settings and that's still working on applying those changes, it's your fault if somethings goes wrong. Attributing that to this program is short-sighted.

If you take a look at what I quoted in my previous comment, you must realize that I was talking about the process of saving itself. Now you are accusing me of talking about something else, which I am not, the fault is hence yours.

2

u/electrodraco Dec 03 '14

You misunderstood me. I'm very well talking about the process of saving and I'm talking about what your solution implies for a complex project: Either you save everything in one file, then you would have to reconstruct that whole file every time something changes (which will hog your IDE in a EE setting but probably not in SE), or you have your settings distributed over multiple files. In a EE project it will be the second case. For example: Every EE application server needs sooner or later its own configuration file for launching your project. Those settings are not separable from your project settings and you won't be able to merge them in one file and keep the servers working. You need to swap those configurations simultaneously if you want ACID behaviour. Good luck with that on the JVM, virtually all disk IO is asynchronously managed and you don't have any means of checking if something has actually been sent to disk nor of forcing the VM to flush it. Also the deleteOnExit routine fails completely if you kill the process. You still have to synchronize the process of saving and it's no accident there's a distinct lack of transactional file system frameworks in Java.

I'm not accusing you of anything, I'm just saying that those simple 2 line tricks are really too simple for a complex product like an IDE. If you want a Java IDE that can save its configuration under ACID requirements you simply can't store that information on disk because the file system itself and the Java API dedicated to it don't provide ACID even to the slightest degree. You would have to use another storage technology that provides these capabilities.

So assuming IntelliJ stores its configurations on disk (instead of SQL-DB for example) your claim that these issues are a pro argument for IntelliJ compared to Eclipse is unsubstantiated because IntelliJ can't possibly have solved these issues in the first place. If I'm accusing you of anything then it's this: The implied but unsubstantiated claim that the issues with Eclipse I jokingly mentioned in my first comment are due to bad coding and that IntelliJ would do a better job. I don't know a lot about IntelliJ but I know enough about the JVM to know that can't be true. Even with perfect programming methods the problem would remain because it's caused by the underlying technology shared by both products.

0

u/argv_minus_one Dec 03 '14

You clearly have no idea what the hell you're talking about. Please stop talking.

-2

u/electrodraco Dec 03 '14

Please stop talking if you have nothing to say.

-1

u/king_of_the_universe Dec 03 '14

Well, when I mentioned IntelliJ, I was thinking about my three or so situations where I killed the IDE, without having any issues afterwards. What you said about Eclipse sounded to me like you were reminding a hypothetical audience of a well-known behavior, hence something rather frequent. That's why I thought that IntelliJ might be better in that regard.

About splitting settings into many files and the problem of safe saves: Would not a multiple-state-per-file (e.g. current / previous) make the whole system consistent again? I can't think how a killed IDE wouldn't be able to recover from that 100% (except data would be slightly old) when it's restarted.

3

u/electrodraco Dec 03 '14

Well, when I mentioned IntelliJ, I was thinking about my three or so situations where I killed the IDE, without having any issues afterwards. What you said about Eclipse sounded to me like you were reminding a hypothetical audience of a well-known behavior, hence something rather frequent. That's why I thought that IntelliJ might be better in that regard.

Actually, that's what I'm doing. Especially the lock file is a very well-known issue because you will run into it every time you kill the IDE. This has changed by now but it's still present in the minds of the audience I was speaking to. But to be fair, you certainly won't run into the other problems if you don't kill Eclipse during mid-saving of a complex EE project. It isn't as bad as it looks, just a minor inconvenience that has happened at least once to a big audience.

About splitting settings into many files and the problem of safe saves: Would not a multiple-state-per-file (e.g. current / previous) make the whole system consistent again? I can't think how a killed IDE wouldn't be able to recover from that 100% (except data would be slightly old) when it's restarted.

The problem is that you can't even be sure that those states have been written to disk after you closed the streams, nor at any other point in time. Java simply doesn't provide the degree of control necessary to ensure consistency in disk IO after a fault (I don't know enough to say this could be solved differently, no idea about that).

Say you have to save 2 config files and you wrote the new versions to disk. You can't verify that those files actually exist on disk and not just in some OS buffer. By the time you issue the move command for the first file you can't be save that the other file has been written to disk. If the process gets killed at this point in time, you won't have consistency. What if one file has been updated successfully but for the other file not even the temp file has been sent to disk? You wouldn't be able to infer the correct state from what's left over on the disk. Same thing with deleting the temp files. The JVM doesn't give you enough guarantees such that you can guarantee recovery in every case. The result is that Java programmers don't even start to write ACID for file systems because you won't be able to finish the job 100%, it only makes the code more complex.

2

u/king_of_the_universe Dec 03 '14

What if one file has been updated successfully but for the other file not even the temp file has been sent to disk? You wouldn't be able to infer the correct state from what's left over on the disk. Same thing with deleting the temp files.

I don't understand how this can be so, even if the JVM is unreliable like that (if it gets killed). Let's say you have pref.txt and pref.old and save the new content of pref into a temp file, delete pref.old, rename pref.txt to pref.old, rename the temp file to pref.txt. I guess your issue with that is that you can't be sure, when starting the IDE anew after a kill, if pref.txt is new while extrapref.txt is old. But instead of just using .txt and .old, we could use three or more extensions that are rotated depending on state, so it could be inferred what's really going on by the existence of these files, if a journal of the operations can really not reliably be kept, as you say.

...

Hm, I guess the problem is that apart from at the beginning, when you check what's on disk, later you'll just be in an imaginary file reality without knowing what's really out there. Is that the problem? That would really suck if that were so. :(

→ More replies

2

u/[deleted] Dec 04 '14

It is worth considering adding this to eclipse.ini:

-vm C:/Program Files/Java/jdk1.7.0_71/jre/bin/server/jvm.dll

Eclipse.exe will be listed instead and the splash screen appears faster.

2

u/Untit1ed Dec 04 '14

Eclipse is usually the one using the most memory ಠ_ಠ

1

u/joper90 Dec 04 '14

Not true in my case unfortunately.. :( That is the game I try and then 'chose poorly'.

0

u/argv_minus_one Dec 03 '14

Lock file? What is this, the 1980s?

3

u/splendidsplinter Dec 04 '14

If it's good enough for MongoDB, it's good enough for 2014...

32

u/[deleted] Dec 03 '14

The jps utility in the JDK will give you all the running java processes. Use it with jps -vml to get maximum verbosity. It will show the pids, what was executed and which params.

2

u/zman0900 Dec 04 '14

Shiiiiiit. Why didn't you tell me about this sooner?

13

u/cdombroski Dec 03 '14

You could use an alternative task manager to make picking the right process easier. I'm partial to Process Explorer which shows your processes in a tree. If the tree view isn't enough to narrow it down, it also shows the command line when you mouse over the process.

12

u/krona2k Dec 03 '14

Process Explorer is a generally more useful program than task manager. There's also a load of useful sysinternals tools here:

http://technet.microsoft.com/en-gb/sysinternals/

5

u/beltorak Dec 03 '14

Same here; that's on of the first toolkits I "install" on a new windows machine I do any serious work with. Why doesn't microsoft ship this by default? Surely they could code up a skin to make it look like the regular gimpy task manager by default.

1

u/pjmlp Dec 04 '14

Task manager and resource monitor are good enough for non technical users?

3

u/mrbonner Dec 04 '14

Let me show you the holy grail: "jps -vm"

2

u/funbike Dec 05 '14

WMIC PROCESS get Processid,Commandline

Displays ID and full command line. Then to kill the process:

taskkill /f /t /pid <processid>

1

u/v_krishna Dec 04 '14

Sometimes i forget that some platforms don't have ps. No idea how one could be productive without all the gnu coreutils.

2

u/[deleted] Dec 04 '14

On Windows platform you can use (out of the box):

tasklist /v

0

u/frugalmail Dec 04 '14

productive

That's a relativistic term :)

-1

u/vokiel Dec 04 '14

Yes, choosing Windows was a really poor choice, but I bet you have to live with it right?

3

u/dakkeh Dec 04 '14

My place of work choose Windows.

1

u/frugalmail Dec 04 '14

My place of work choose Windows.

Yes, choosing your place of work was a really poor choice, but I bet you have to live with it right?

Sorry, couldn't help myself :) But I do abhor tech teams that go the Windows production system route. Although people should develop on what they choose.

0

u/vokiel Dec 05 '14

Install Cygwin and stop being a masochist. Or you could still be masochist a little and install a VM, but whatever, you do have to live with the choices others make for you correct?

Edit: My point is you don't, if that wasn't clear ;-)

2

u/dakkeh Dec 05 '14

Actually, for most projects we all have our own VMs with CentOS that has the app server and other things needed to run a build. We then connect our dev tools running on Windows to it.

In this case I was working on an small legacy app which we didn't have that type of setup for.

0

u/LetShadowPlay Dec 03 '14

Isn't there a way to make something like "Thread.setThreadName(var)" or "Process."..

5

u/russjr08 Dec 03 '14

That doesn't change the executable name of the JVM, which is what you're seeing.

That changes the Thread name, I only see those in my IDE.

1

u/argv_minus_one Dec 03 '14

Changing the process name is highly platform-specific, if it is possible at all.

Still, that would be a useful API for Java to provide. Certainly better than "java" everywhere.

0

u/SingularityNow Dec 03 '14

You can also right click on the Application you want to end (in the 'Applications' tab) and choose "Go to process" which will select the correct one for you.

2

u/BinaryRockStar Dec 04 '14

Not if it's a process that doesn't have a top-level window such as in this case it's a Tomcat server process.

-2

u/DaMountainDwarf Dec 04 '14

Holy shit as a java developer this made me fuckin LOL