Running a Java Swing application with a double click (no console)

Suppose I have an executable JAR that runs the Swing GUI. If it starts from the console (for example, java -jar myapp ), the console is also used by the application (i.e. logs are printed). This magazine takes a little time, it is quite verbose.

Please note that I only have JARs, not sources.

Question: what happens when you double-click to launch a JAR? Obviously, the logs are not visible, but are they simply invisible or does it really increase application performance (skipping logging)?

+4
source share
4 answers

System.out.prinln() prints to the process output. The JVM does not know or care about where the exit goes. It can be a console, or it can be redirected to a file or transferred to another process or sent to nowhere. An instruction is a blocking operation, so the time taken to execute a command depends on where it actually goes. Printing to the console is slower than printing to a file, which is slower than printing to nowhere.

+1
source

If you do not want to see the console, use javaw to run the program instead of java . So you run: javaw -jar myapp.jar

+4
source

If you intend to stop logging, you can disable logging using Logger#setLevel(Level.OFF) (assuming you are using a standard logger). If you intend to reduce the number of text messages, you can use Level.WARNING, for example, for which only WARNING and SEVERE messages are logged. As a rule, you can set a minimum level for entering any level. When your application starts without a console, Console usually not tied to it (but I think this is a platform problem, for example, some platforms can provide center consoles, which, it seems to me, while Java web applications work in servlet containers , even if the container was launched from the console, as a rule, it is not connected to the console), so I will not argue with my code for any reason. If you still want your logs in an application that did not have a Console attached at run time, you can always redirect your log messages to a file using Logger#addHandler(FileHandler) .

+3
source

Normally System.out.println() not preferred for logging. This is an IO operation and takes a lot of time. If you need to disconnect, you need to comment on this manually.

Use log4j or java logger.

+2
source

All Articles