public final class Restarter
extends java.lang.Object
You can influence the behavior by setting Java properties;
restart.max.32bit
: maximum size used for 32bit JVMs. When I first
implemented the restarter, 1700000000
(1.7GB) was a good value. But
modern JVMs seem to use more memory for themselves, so nowadays the default
used is only 1400000000
(1.4GB). Switch to a 64bit JVM if possible.
debug.restart
: if set to true
, additional debugging information is
print to console.
no.restart
: if set to true
, restarting is not done. This can be
useful when you debug your application, because debuggers connect to the original
app, not the restarted one.
restart.mem.part
: this defines the default part of the memory used for
the application. This default is used when no method explicitly defining this
part (parameter memPart
) is used. Values are between 0.0
and 1.0
.
Modifier and Type | Field and Description |
---|---|
static double |
DEFAULT_MEMORY_PART
Default part of memory to reserve for the application.
|
static long |
MAX_32BIT_SIZE
Max size to use for 32bit JVMs (
restart.max.32bit . |
static java.lang.String |
PROPERTY_DONT_RESTART
Property which can be set to
"true" in order to don't restart under any circumstances. |
(package private) static java.lang.String |
PROPERTY_FORMAT
Pattern for formatting properties.
|
static java.lang.String |
PROPERTY_JAVA_CLASSPATH
The Java class path property.
|
static java.lang.String |
PROPERTY_JAVA_HOME
The Java home property.
|
static java.lang.String |
PROPERTY_JAVA_VM_NAME
The Java virtual machine name property.
|
static java.lang.String |
PROPERTY_RESTARTED
Property set by the restarter when starting a child process.
|
Modifier and Type | Method and Description |
---|---|
static void |
addSystemProperties(java.util.Collection<java.lang.String> commandLine)
Add the system properties to the command line arguments.
|
static java.lang.String |
getJavaCommand()
Get the java command with which the JVM was started.
|
static long |
getPhysicalMemorySize()
Get the amount of physical memory on this machine.
|
static boolean |
is64BitJVM()
Check whether the JVM running this class is 64bit.
|
static void |
main(java.lang.String[] args)
Test code.
|
static boolean |
possiblyRestart(java.lang.Class<?> mainClass,
double memoryPart,
java.lang.String... args)
Possibly restart the program using improved memory settings.
|
static boolean |
possiblyRestart(java.lang.Class<?> mainClass,
java.lang.String... args)
Possibly restart the program using some 75% of available memory.
|
static boolean |
possiblyRestart(java.lang.String mainClassName,
double memoryPart,
java.lang.String... args)
Possibly restart the program using improved memory settings.
|
static boolean |
possiblyRestart(java.lang.String mainClassName,
java.lang.String... args)
Possibly restart the program using some 75% of available memory..
|
public static final java.lang.String PROPERTY_RESTARTED
public static final java.lang.String PROPERTY_DONT_RESTART
"true"
in order to don't restart under any circumstances.public static final java.lang.String PROPERTY_JAVA_HOME
public static final java.lang.String PROPERTY_JAVA_CLASSPATH
public static final java.lang.String PROPERTY_JAVA_VM_NAME
public static final long MAX_32BIT_SIZE
restart.max.32bit
.public static final double DEFAULT_MEMORY_PART
restart.mem.part
to something between 0.0
(no memory) and 1.0
(all memory).
If property is not defined or has an insane value 0.75
is used.static final java.lang.String PROPERTY_FORMAT
public static boolean possiblyRestart(@NotNull java.lang.Class<?> mainClass, java.lang.String... args)
This method only returns if it did not restart the program, either because the program was already restarted, or because there were errors which kept the program from being restarted.
mainClass
- main class to startargs
- program argumentstrue
if the program was already restarted, or there are no better memory settings availablefalse
if there are problems keeping the program from being restartedpublic static boolean possiblyRestart(@NotNull java.lang.Class<?> mainClass, double memoryPart, java.lang.String... args)
This method only returns if it did not restart the program, either because the program was already restarted, or because there were errors which kept the program from being restarted.
mainClass
- main class to startmemoryPart
- part of physical memory to useargs
- program argumentstrue
if the program was already restarted, or there are no better memory settings availablefalse
if there are problems keeping the program from being restartedpublic static boolean possiblyRestart(@NotNull java.lang.String mainClassName, java.lang.String... args)
This method only returns if it did not restart the program, either because the program was already restarted, or because there were errors which kept the program from being restarted.
mainClassName
- full name of main class to startargs
- program argumentstrue
if the program was already restarted, or there are no better memory settings availablefalse
if there are problems keeping the program from being restartedpublic static boolean possiblyRestart(@NotNull java.lang.String mainClassName, double memoryPart, java.lang.String... args)
This method only returns if it did not restart the program, either because the program was already restarted, or because there were errors which kept the program from being restarted.
mainClassName
- full name of main class to startmemoryPart
- part of physical memory to useargs
- program argumentstrue
if the program was already restarted, or there are no better memory settings availablefalse
if there are problems keeping the program from being restartedpublic static void addSystemProperties(@NotNull java.util.Collection<java.lang.String> commandLine)
commandLine
- command line argumentspublic static long getPhysicalMemorySize()
0L
if the amount is unknown@Nullable public static java.lang.String getJavaCommand()
null
if the command couldn't be determinedpublic static boolean is64BitJVM()
true
if this is a 64bit machine,false
if this is a 32bit machinepublic static void main(java.lang.String[] args)
args
- arguments (unused, but should be passed through)