I have searched many places of making IPv6 enabled to have a dual-stack machine IPv6.
I found many have answered to set java.net.preferIPv6Addresses=true which is set to false by default.
I want to know where exactly should I make these changes, i.e in which file or do I have to write some Java code to put this into.
The setting needs to get into the JVM's system properties ... and it needs to be there before the relevant part of the Java class library initializes.
The "bomb proof" way to do this is to pass the setting to the JVM as a command line parameter; e.g.
java -Djava.net.preferIPv6Addresses=true ... com.example.MainClass <args>
You could also code your application to inject the setting using
System.setProperty("java.net.preferIPv6Addresses", "true");
but you need to ensure that the injection happens soon enough1, and that would not be trivial.
1 - "Soon enough" means before JVM networking code's static initialization has occurred. This can be difficult to achieve in a complex application. Note the the Network Properties documentation states: "Some are checked only once at startup of the VM, and therefore are best set using the -D option of the java command ...". Note that it does NOT state that those properties can only be set that way.
The suggestion of using a JAVA_OPTS environment variable will only work for some applications. The handling of JAVA_OPTS will happen in your application's launcher or wrapper script before the JVM is launched. The same applies to _JAVA_OPTIONS ... which is one that I've not seen before.
(If the application you are using is properly documented, then its documentation should explain how to specify options that need to be passed to the java.exe launcher.)
The standard java.exe and javaw.exe commands certainly DO NOT pay any attention to the JAVA_OPTS environment variable.
you must put in in your enviorment path before running the java executable.
in linux
export JAVA_OPTS="-Djava.net.preferIPv4Stack=true" (same for ipv6 )
Related
Is there a way to identify the JVM's default time zone without running a Java program on it? Are there any commands available using which I can take a look at it?
Yeah we all know what jvm is , but maybe author want to know what is a default timzeone of running jvm without restarting it and deploying code on it.
In such case you could maybe check command line of java process for properties (user.timezone) or connect to jvm via some tool like visual vm and check this property, I am not sure if there is some other way to do that.
If you have remote debugging enabled then it should be easier as you can connect via your favourite ide/tool and just evaluate default timezone.
I can't believe I couldn't find this on the web, I must have been using some bad search terms...
Anyway, is there any way to set some default arguments for the JVM. I'm running JRE 1.8.0_73 if it makes much difference.
The goal I am trying to achieve is attaching an agent to every instance of the JVM that starts, in this particular case an applet. I know I could start the applet from the command line and specify the arguments there but I would like to know if there is a way to globally set some command line arguments.
Thanks!
You can create a system environment variable named _JAVA_OPTIONS and set its value to all the default arguments you need to pass to the JVM.
Hi I need to see eclipse's running configuration in a simple java project. for example print them as key value pairs at console would be enough
[EDIT]: the reason for this
I added a parameter to eclipse.ini but I'm not sure about the value whether it is passed as I expect or not
and the parameter I'm looking for is
-Dorg.eclipse.swt.browser.XULRunnerPath=xulrunner
You have two ways for getting the details
http://www.mkyong.com/java/how-to-list-all-system-properties-key-and-value-in-java/
In case it is java parameters
Read Java JVM startup parameters (eg -Xmx)
From your updated response.
I will suggest that you check your memory manager.
In windows that will be task manager
mac that will be Activity Monitor
on linux you can fire top command from command line
Still not satisfied, check over this StackOverflow thread
Monitoring own memory usage by Java application
Still not satisfied. I would suggest profiling of the application using yourkit profiler or any other java profiler.
When you start yourkit it shows the java applications running. Simply click on one of it and it will initate profiling for you.
Eclipse runs on a JVM, which is not the same JVM where your program will run.
It would be easier to find the configuration file (eclipse.ini I guess is what you are looking for), since they will not be environment settings for the JVM where your code will run.
all runtime configuration endsup being a java argument or a system property passed
so you can print all the commandline argument passed in to java + all the System properties and its values (may be with filtered set of key value based on your interest)
I typically debug my application by starting a WebLogic process from within IntelliJ IDEA. Both of these application provide ways of specifying optional memory arguments (e.g., -Xms1024m -Xmx2560m -XX:PermSize=1024m, etc.) to the Java command line, and there are various environmental variables (e.g., JAVA_OPTIONS) that might also come into play.
How can I determine which of these specified options "won", i.e., from within the Java process, how can I find out the memory specifications imposed on the Java process? None of the system properties I've seen seems to show them.
If you use jconsole (which comes with the java jdk) to connect to your webserver:
jconsole <pid>
You can go to the VM Summary tab to see all of the VM Arguments passed to your webserver. This will also show you current and maximum heap size. If you have duplicated arguments, generally speaking the last memory argument in the list is what is used. You can check here if you have more questions about that.
Duplicated Java runtime options : what is the order of preference?
I want to modify the default jvm setting, like gc policy and Xmx.
Because of some reason, I can't modify the starting command of java program to add these setting.
Is there any ways to do that?
Thanks.
[updated]
Sorry I didn't describe it clearly.
It is something like server side job program which is started from another server program. Because of the default Xmx is too big(on 64 bit server), minor GC time is too long, almost 1 second. So I want to change the default GC policy to test.
And for now, the server program can't be modified.
You can have the Java program relaunch itself. You can have a bootstrap main which is called first. It then does a Runtime.exec(...) with the command line option you require running a different Class.main() which is the actual program.
Short answer: with your requirements you can't do this.
Theoretically you have 2 possibilities:
Provide settings via comand line options:
I can't modify the starting command of java program to add these setting
Change settings at run time:
But it's impossible