Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to launch from Eclipse in Low priority under Windows?

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.

like image 918
adum Avatar asked Sep 24 '08 03:09

adum


2 Answers

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.

like image 133
George Forman Avatar answered Sep 19 '22 17:09

George Forman


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.

like image 23
Daniel Spiewak Avatar answered Sep 21 '22 17:09

Daniel Spiewak