How to launch from Eclipse in Low priority under Windows?
Asked Answered
Y

8

6

I'm running programs from Eclipse (on Windows) that eat a lot of CPU time. To avoid bogging down my whole machine, I set the priority to Low with the Task Manager. However, this is a cumbersome manual process. Is there a way Eclipse can set this priority automatically?

EDIT: I realized that each particular launcher (Java, Python etc) has its own configuration method, so I will restrict this question to the Java domain, which is what I need most.

Yacht answered 24/9, 2008 at 3:46 Comment(0)
V
5

I have the same problem on Windows--- launching subprocesses that use all the CPUs (thread-parallel jobs), yet I want good responsiveness in my Windows development environment.

Solution: after launching several jobs:

DOS cmd>> wmic process where name="javaw.exe" CALL setpriority "below normal"

No, this won't affect eclipse.exe process.

Java Solution: Insert this code into your CPU-intense programs to lower their own Windows priority:

public static void lowerMyProcessPriority() throws IOException {
    String pid = ManagementFactory.getRuntimeMXBean().getName();
    int p = pid.indexOf("@");
    if (p > 0) pid = pid.substring(0,p);
    String cmd = "wmic process where processid=<pid> CALL setpriority".replace("<pid>", pid);
    List<String> ls = new ArrayList<>(Arrays.asList(cmd.split(" ")));
    ls.add("\"below normal\"");
    ProcessBuilder pb = new ProcessBuilder(ls);
    pb.start();
}

Yes, tested. Works on Win7.

Varner answered 8/12, 2016 at 18:33 Comment(2)
thanks. the dos cmd is very helpful for batch stuff :)Bali
Very helpful, still works under Windows 10, and elevated process is not required nor UAC prompts :-)Economy
I
2

I'm assuming that you launch these programs using External Tools. If so, then you can modify the launch command to use the start /low hack described earlier. However, if these applications have a special launch type (like Java Application or similar), then you're in trouble. The only way you could actually change this would be to crack open the source for Eclipse, find that launch type and where it dispatches tasks and then modify it to use start /low. Sorry, but I don't think there's a simple solution to this.

Igraine answered 24/9, 2008 at 20:4 Comment(0)
P
0

A better alternative is configure the amount of memory that Eclipse will use: http://www.eclipsezone.com/eclipse/forums/t61618.html

And do a google search about -Xmx and -Xms parameters for JVM (which you could configure for runners inside Eclipse).

Kind Regards

Porte answered 24/9, 2008 at 3:51 Comment(1)
i have no need to change the memory usage actually, which is easy as you say. i am running CPU-intensive programs.Yacht
R
0

I spent some time a while back to investigate this. There is no method inside Java to lower the priority (as far as I could see), so you need to employ the "start /min" approach. I didn't try to get that working.

Instead I got a multi-kernel processor. This gives room for other stuff, even if a Java program runs amok on one kernel.

Strongly recommended.

Regiment answered 11/1, 2009 at 19:18 Comment(0)
T
0

I would like this as well, odd that it is not possible, really. I know you can set thread-priorities, but I think in windows-land, threads are all scheduled "inside" the process priority so to speak.

Terrill answered 11/5, 2010 at 17:49 Comment(0)
M
0

I've run into the same question in Linux and have found this: http://tech.stolsvik.com/2010/01/linux-java-thread-priorities-workaround.html

The interesting bit is about how to convert Java thread priorities to OS priorities. This has solved the problem for me, it may help you too.

Monachism answered 31/1, 2012 at 6:39 Comment(0)
S
0

Use an OS tool or a fake java.exe to capture the really long javaw.exe command that the eclipse launcher spawns.

Bypass eclipse.exe and launch the javaw.exe directly.

Once you have the javaw.exe launching directly and correctly.

START /BELOWNORMAL \path\javaw.exe lots-of-parameters-to-load-workspace

Syndicalism answered 8/11, 2017 at 21:30 Comment(0)
T
-4

If you need it only in development you can set the priority of all other processes to high...

Trincomalee answered 1/9, 2010 at 8:1 Comment(1)
If setting one is cumbersome..wouldn't setting all others even worse?Illyricum

© 2022 - 2024 — McMap. All rights reserved.