Eclipse takes too long to start Program Execution - java

When I click the "Run" button or the F11 key to start a program execution it takes around 8-10 seconds to start the actual execution.
So considering the following same code
public class Demo {
public static void main(String[] args) {
System.out.println("Hello World");
}
}
After clicking the "Run" button or the F11 key it prints "Hello World" after 8-10 seconds. For bigger programs once the execution has started it runs fairly quick. But the initial starting is the only issue
I am using "Eclipse IDE for Java Developers"
Version: 2020-03 (4.15.0)
Have only a minimal set of plugins and infact tried disabling the Mylyn plugin as well but to no avail

This is probably not caused by Eclipse, which can be seen by whether the delay also occurs when running on the command line what you get with the Show Command Line button of the run configuration.
On Windows, it can be caused by the Windows Defender. Excluding the Java installation folder as described here (which will probably be the main reason for you, since Windows Defender scans the entire Java system library on access) and excluding the folders containing the dependencies (e.g. Maven repository) should eliminate the delay. But keep in mind that this also comes with a security risk, especially the exclusion of a Maven repository, where you usually don't pay attention attention to what you download into it.
Startup time can be further reduced by using newer Java VMs or/and using an Eclipse OpenJ9 Java VM with shared classes cache (for me Eclipse and other Java applications start with OpenJ9 in about two thirds of the time than with the HotSpot VM).

Found the issue. It was Dynatrace agent that was causing the problem.
Thanks to #howlger for directing to execute via the "Show Command Line" on the command line, which established the fact that the issue was not caused by Eclipse.
Running the java command with -verbose flag showed the following 3 jars getting loaded
[Opened
C:/PROGRA~2/DYNATR~1/oneagent/agent/bin/1.175.224.20190905-115725/any/oneagentjava.jar]
[Opened
C:/PROGRA~2/DYNATR~1/oneagent/agent/bin/1.175.224.20190905-115725/any/oneagentjava.rmi.jar]
[Opened
C:/PROGRA~2/DYNATR~1/oneagent/agent/bin/1.175.224.20190905-115725/any/oneagentjava.sql.jar]
And then uninstalling the Dynatrace Agent did the trick
Now the program execution starts immediately from command prompt as well as Eclipse

Related

Why is Java crashing (exit code 134)?

I'm trying to get started with LWJGL 3, but it doesn't even run the sample program. It just crashes the JVM (error code 134, SIGABRT, JVM tries to access memory at address 0).
I've reinstalled Gradle, made sure it uses the right Java version and re-downloaded the LWJGL script, but to no avail.
EDIT: I updated Java to the latest version, but it still doesn't work...
I used the default Java app Gradle config and the sample program (linked above).
The expected behaviour is the app running, opening a window, etc., but instead Java crashes.
Execution failed for task ':run'.
> Process 'command '/Library/Java/JavaVirtualMachines/jdk1.8.0_101.jdk/Contents/Home/bin/java'' finished with non-zero exit value 134
The sample program uses GWT (Java GUI - graphic interface). It requires xorg server running on Linux (if you are on Linux). See the answer JVM error: Process finished with exit code 134 (interrupted by signal 6: SIGABRT)
I have had this same issue (exit value 134) before, but maybe in a slightly different context: in Android Studio running on a Ubuntu machine. When this happened, I also saw an error log file produced under the ./app folder, named “hs_err_pid[a number].log”. This log file provided more info about the error. However, I still couldn’t figure out a solution by reading the log file.
Since this error does not always happen to me, I’ve tried 2 brute-force methods:
Method #1. Remove the ./build folder
Method #2. In Android Studio, → File → Invalidate Cashes / Restart…
It appears that the error can be avoided by using one of, or a combination of, these 2 methods.
Not sure if its relevant but I faced the same issue while trying to run some introductory code on my Mac. For me the issue seemed to be around library version configurations. I was earlier using these:
project.ext.lwjglVersion = "3.2.3"
project.ext.jomlVersion = "1.10.4"
And later changed it to this (As per the LWJGL library customisation page)
project.ext.lwjglVersion = "3.3.1"
project.ext.jomlVersion = "1.10.4"
Further, I also added the VM option: -XstartOnFirstThread
But that was for a different error only as far as I understand.

Internal error in eclipse when running java program

Eclipse froze on me earlier today, so I typed "top" into the command prompt and killed it. Now when I try to run a java application, I get this error:
eclipse\plugins\org.eclipse.jdt.debug_3.7.0.v20110509
That's all that shows up under details.
None of my previously working programs run, and I have no clue what this is. I have Eclipse 1.5.0 running 1.6 and 1.7 Java, depending on what program. Thanks for any help.
It is possible that you killed part of the process but not all of it. It is possible that a java process is running with a reference to this job. I would try restarting your computer to see if it will stop whatever process is referencing that jar.
Aside from a restart, then another option would be to use (in linux) pstree, filtered for your user to see if any other jobs are referencing that jar and/or java.
EDIT:
Another path is to look at log files. On linux they are in /var/log. Here's a link in that direction: http://docs.oracle.com/javase/7/docs/webnotes/tsg/TSG-Desktop/html/felog.html

Using Bumblee (Graphics Drivers) with Eclipse IDE [duplicate]

Does anyone know how to make eclipse or netbeans use the graphics card in optimus laptops by invoking optirun (bumblebee) inside the IDE so that one can just use the run button in the IDE to run the program in a graphics card within the IDE.
In simplest form I just want the IDE to do the equivalent of optirun ./javaproject
The way I did this in Eclipse was to first start the Java debugger jdwp and listen to a port. Then start the JVM with optirun java ... and use jdwp to connect to this port. Both tasks can be started at the same time in Eclipse by creating a Launch Group in the debug configuration settings (Run -> Debug Configurations). In detail:
Create a Remote Java Application debug configuration with "Standard (Socket Listen)" Connection Type and some arbitrary port, e.g. 56789. This attaches the Java debugger jdwp on port 56789 to a virtual machine which accepts debug connections at this port.
Now we need to start a JVM with optirun. This can be done with a External Tool Configuration (Run -> External Tools -> External Tool Configurations). Create a new Program configuration in the left side of the External Tools Configurations window. You could directly start optirun java <additional arguments> by filling in the required fields. However, I have decided to use a shell script which is reusable by different projects (As can be seen below, there is one part missing to make it entirely reusable. I'm glad for any help from more experienced Eclipse users...). Hence, the Location field points to this shell script. The script itself accepts three arguments: the classpath for the project, the name of the Java executable, and the port number. These arguments can be passed to the script in the Arguments field of the Main tab, e.g.
${project_classpath:${selected_resource_name}}
ExecName
56789
The shell script looks like this, assuming optirun is in your PATH:
#!/bin/sh
CLASS_PATH=${1}
JAVA_EXECUTABLE=${2}
PORT=${3}
# TODO: fix this java library path: pass it as an argument as well. Is there an Eclipse variable which stores this?
JAVA_LIBRARY_PATH=/usr/local/share/OpenCV/java
#------------------------------------------------------------------------------
optirun ${JAVA_BIN} -agentlib:jdwp=transport=dt_socket,suspend=y,address=localhost:${PORT} -Djava.library.path=${JAVA_LIBRARY_PATH} -Dfile.encoding=UTF-8 -classpath ${CLASS_PATH} ${JAVA_EXECUTABLE}
#------------------------------------------------------------------------------
Finally, the two pieces are brought together in a Launch Group in the Debug Configurations window (Run -> Debug Configurations). Create a new Launch Group and add the two previously generated Debug configurations by clicking on Add in the Launches tab and by selecting the appropriate configurations.
Note that due to the classpath variable in step 2 (i.e. ${project_classpath:${selected_resource_name}}), the appropriate package needs to be selected in the Package Explorer before clicking on the run debug configuration button (make sure that the Launch Group is selected).
This solution works perfectly for me: I can debug Java code inside Eclipse which calls native code involving CUDA optimizations and Bumblebee only activates the discrete graphics card when necessary.
Just use optirun to start the IDE. For example, optirun eclipse or optirun netbeans
I build the project in Netbeans (F11) and run the following in a terminal:
optirun java -jar path/to/javaproject/dist/javaproject.jar
Mind that if you have any java parameters in your project, you need to add it manually. My workflow is like this:
Locate the Java options from the project, open Project -> Properties, Run. At VM Options I see -Djava.library.path=lwjgl/native/windows;:lwjgl/native/linux. I also have some parameters that I want to pass to main(String[]). With this information, I open a terminal and run:
cd path/to/javaproject
optirun java -Djava.library.path=lwjgl/native/windows;:lwjgl/native/linux \
-jar dist/javaproject.jar some paremeters
Another hint, if you have to open and close the program frequently, run optirun bash in a different tab so that preparing the use of the graphics card becomes faster. Alternatively, you can run optirun netbeans, but that means that the nvidia card will always be on even if you are programming which increases power use and increase the heat.
Important: if you are using a 32-bit JVM or Java libraries on a 64-bit machine, you also need to install the 32-bit drivers and libraries. For Ubuntu, the nvidia package already contains 32-bit drivers, see this answer. For other distros, you likely need to install lib32-* packages for Mesa, VirtualGL and nvidia-utils.
You can also rename java to java_real and use this portion of code as your java command :
#!/bin/bash
path=$(dirname $(readlink -f $0))
args=""
runner="$path/java_real"
for var in "$#"
do
if [ "$var" = "-3d" ]; then
runner="primusrun $runner"
else
args="$args $var"
fi
done
$runner $args
NOTE : I had to do this in /usr/lib/jvm/java-7-openjdk-amd64/jre/bin, not in /usr/bin to make it work with Eclipse.
In Eclipse, just add "-3d" in your program arguments and you're good to go !

Why won't the VisualVM Profiler profile my application?

I've created a simple 1 file java application that iterates through a loop, calls some functions, allocates some memory, adds some numbers, etc. I run that application via eclipse's Run As->Java Application.
The running application shows up in Java VisualVM under Local.
I double click on that application and go to the Profiler tab.
The default settings are:
Start profiling from classes: my.main.package.**
Do not profile classes: java.*, javax.*,
sun.*, sunw.*, com.sun.*
I click on CPU. The CPU and Memory buttons gray out. Nothing happens.
The Status says profiling inactive.
When my application terminates the Status says application terminated.
What am I doing wrong here? Are there some settings I need to tweak? Do I need to set a VM flag when I launch my application?
I had the same issue after java 1.7.0_45 update. I had to delete the following folder:
C:\users\'username'\AppData\Local\Temp\hsperfdata_'username'
After doing so, everything works like a charm.
I'd guess the issue relates to the application being started from within Eclipse, this is because JVisualVM expects to find data in the java.io.tmpdir directory (usually C:\Users\[your username]\AppData\Local\Temp\hsperfdata_[your username] on a Windows system).
I assume rather than in the normal location where JPS, JVisualVM etc. expects it, Eclipse puts the data in it's own temp folder?
If so, try invoking JVisualVM using jvisualvm -J-Djava.io.tmpdir=[Eclipse's temp directory] to explicitly tell it where that data is.
If you can't find the hsperfdata_$USER folder, try just running your application outside Eclipse in the usual command line Java way.
Also note that there was a bug affecting the temp folder (case sensitivity) introduced around 1.6.0_23, so maybe you'd benefit by updating to a more recent Java 6 (or 7) build?
Mikaveli, Kuba and Somaiah Kumbera have provided great solutions. Just adding what I have done to make things work.
I first checked the location C:\users\'username'\AppData\Local\Temp\hsperfdata_'username' There was no file named with the process ID of my program running inside eclipse.
I simply stopped the program and added the following parameter to the Run Configurations of the program (Run Configurations -> Arguments -> VM Arguments)
-Djava.io.tmpdir=C:\users\'username'\AppData\Local\Temp\hsperfdata_'username'
I started the program again. Still could not profile it. But now I have a file created for the process at the given temp directory.
Then, a simple restart of VisualVM did the trick.
I had the same issue, but with the following symptoms:
I started jetty, with the work directory in
C:\Users\t852124\AppData\Local\Temp
Jetty was creating the hsperfdata_ directory but not setting a processID in it
So when I started visualVM, it could not get any java process info.
I solved this by starting jetty with the -Djava.io.tmpdir=C:/temp/java option.
Now when I started jetty, the process ID was created as a file in the hsperfdata_ directory.
So when I started visualVM, it was able to see my local java process
I had the same problem and running VisualVM with elevated privileges (admin rights) solved the issue.
On Linux with VisualVM 1.3.3 I have to remove local settings of application in ~/.visualvm/1.3.3/ to enable CPU Profiler and CPU Sampler.
Also note that /usr/bin/jvisualvm contains hardcoded path to OpenJDK (set with jdkhome variable), which seems to cause a lot of issues, comparing to running to Oracle JDK 1.7.
Also note that if your application is using a recent non-Oracle JVM, you may need to download the "bleeding edge" VisualVM from github.
For example, the VisualVM bundled with JDK 1.8.0.111 doesn't seem to work with the IBM 1.8 JVM. Possibly the IBM JVM was simply released after the Oracle 1.8 JVM, so including the necessary changes wasn't possible at that time.

Eclipse Command Line Java

I would like to see the command that Eclipse is running when I hit run for a Java program. I've looked around the Eclipse preferences for Run/Debug (and console) and the Run Configurations, but to no avail. How can I see the line that Eclipse is using to launch?
In JBuilder, it was the first line in the output.
Edit: I'm not asking whether it uses javac to compile and then java to run. I want to see the line that starts with java and has all the flags, etc. I'm not asking "what does Eclipse run?" since I already know that. I want to see it in a specific case in a specific project.
Set up a launch configuration, then run or debug it.
Go to the "Debug" window of the Debug perspective, the one that shows all the processes and threads.
Right click on the java.exe or javaw.exe item in the tree (its at the bottom under all of the threadgroups and threads), and choose "Properties" on that guy.
You should get a window that contains 2 sections, the left being a list of items, including "process information" and "vm capabilities"
The process information section has 3 sections, showing the time it launched the session, the path to the exe, and the full command line that eclipse used to start the VM. The command line will include everything, including library paths, classpaths, the debug info it passes to the VM, any custom args you pass, etc.
I think that's what you're looking for.
On Unix systems you can see the command line with
ps -e x | grep java
For example (line wrapped for readability):
24925 pts/6 Sl 0:16
/usr/lib/jvm/java-6-openjdk/bin/java
-agentlib:jdwp=transport=dt_socket,suspend=y,address=localhost:53880
-Dfile.encoding=UTF-8
-Xbootclasspath:/usr/lib/jvm/java-6-openjdk/jre/lib/resources.jar
:/usr/lib/jvm/java-6-openjdk/jre/lib/rt.jar
:/usr/lib/jvm/java-6-openjdk/jre/lib/jsse.jar
:/usr/lib/jvm/java-6-openjdk/jre/lib/jce.jar
:/usr/lib/jvm/java-6-openjdk/jre/lib/charsets.jar
:/usr/lib/jvm/java-6-openjdk/jre/lib/rhino.jar
:/usr/share/java/gnome-java-bridge.jar
-classpath /home/hendrik/workspace/webflag/WEB-INF/classes
:/home/hendrik/workspace/webflag/WEB-INF/lib/log4j.jar
:/home/hendrik/workspace/webflag/WEB-INF/lib/junit.jar
nhb.webflag.importtools.tools.ImportArmoryCharacter
-agentlib specifies the debugging connection, -Xbootclasspath is based on the JDK configuration, -classpath based on the build path settings of the project
If it can find any class with the main method, it runs that using "java com.example.Main" where Main is the class with main method.
If you have many classes with main method, then eclipse gives you an option to choose one.

Categories

Resources