https://github.com/chrisgleissner/jisolate
Java Code Isolation
https://github.com/chrisgleissner/jisolate
classloader classloader-isolation isolation java java-11 java-8 vm-isolation
Last synced: about 1 month ago
JSON representation
Java Code Isolation
- Host: GitHub
- URL: https://github.com/chrisgleissner/jisolate
- Owner: chrisgleissner
- Created: 2013-03-25T22:43:52.000Z (about 12 years ago)
- Default Branch: master
- Last Pushed: 2021-04-26T18:06:15.000Z (about 4 years ago)
- Last Synced: 2025-03-24T15:11:22.665Z (about 2 months ago)
- Topics: classloader, classloader-isolation, isolation, java, java-11, java-8, vm-isolation
- Language: Java
- Homepage:
- Size: 70.3 KB
- Stars: 16
- Watchers: 2
- Forks: 3
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE-2.0.txt
Awesome Lists containing this project
README
# Jisolate
[](https://travis-ci.org/chrisgleissner/jisolate)
[](https://coveralls.io/r/chrisgleissner/jisolate)Jisolate is an API for isolating Java classes using either classloader or VM isolation.
## Why Isolation?
Isolates are useful to load the same class multiple times, typically using different configurations.
For example, some frameworks are configured using static singletons. For tests, it is often useful
to start multiple instances of these frameworks, each with its own configuration.## Classloader Isolation
Classloader isolation uses a child-first classloader combined with thread-local system properties
to ensure that non-JDK classes can be loaded multiple times in the same JVM.Classloader isolation is the isolation approach of choice as it is the most performant approach of ensuring isolation
and allows for an easy way to communicate results from the isolated code back to its invoker.```java
Jisolate.classLoaderIsolation()
.withIsolatableClass(IsolatedClass.class)
.withIsolatableArguments("foo")
.isolate();
```## VM Isolation
VM isolation spawns a child VM process. This provides even better isolation than the classloader approach,
but it takes slightly longer to setup.```java
Jisolate.jvmIsolation()
.withMainClass(IsolatedClass.class)
.withMainClassArguments("foo")
.isolate();
```#### Lifecycle control
VM isolation also allows for forcefully terminating the isolated JVM process when it's no longer needed:
```java
try (JvmIsolate isolate = Jisolate.jvmIsolation()
.withMainClass(IsolatedClass.class)
.withMainClassArguments("foo")
.isolate()) {
// The isolated JVM is automatically terminated on leaving this block
}
```## JSR-121
Jisolate is not an implementation of JSR-121, the Application
Isolation API Specification. Instead, it is a light-weight and pragmatic approach of providing
a best effort isolation of Java classes that is useful for many scenarios.