|
| 1 | +# JVM API |
| 2 | + |
| 3 | +Helpers for locating the bundled runtime and configuring the JVM before the first |
| 4 | +database or server is created. |
| 5 | + |
| 6 | +!!! warning "Configure once per process" |
| 7 | + JVM options are locked after the JVM starts. Call `start_jvm(...)` before the |
| 8 | + first `create_database(...)`, `open_database(...)`, or `create_server(...)`. |
| 9 | + |
| 10 | +## Overview |
| 11 | + |
| 12 | +The `arcadedb_embedded.jvm` module provides three public entry points: |
| 13 | + |
| 14 | +- `start_jvm(...)` to configure and start the bundled JVM explicitly |
| 15 | +- `shutdown_jvm()` to shut down a JVM started in the current process |
| 16 | +- runtime location helpers for jars and the bundled JRE library |
| 17 | + |
| 18 | +## start_jvm |
| 19 | + |
| 20 | +```python |
| 21 | +from arcadedb_embedded.jvm import start_jvm |
| 22 | + |
| 23 | +start_jvm( |
| 24 | + heap_size="8g", |
| 25 | + jvm_args="-XX:MaxDirectMemorySize=8g", |
| 26 | + common_pool_parallelism=8, |
| 27 | +) |
| 28 | +``` |
| 29 | + |
| 30 | +**Parameters:** |
| 31 | + |
| 32 | +- `heap_size` (`Optional[str]`): Maximum JVM heap, for example `"4g"` or `"4096m"` |
| 33 | +- `disable_xml_limits` (`bool`): If `True`, relaxes JDK XML entity limits for large XML imports |
| 34 | +- `jvm_args` (`Optional[Iterable[str] | str]`): Additional JVM flags as a string or iterable |
| 35 | +- `common_pool_parallelism` (`Optional[int]`): Explicit cap for `ForkJoinPool.common.parallelism` |
| 36 | + |
| 37 | +**Raises:** |
| 38 | + |
| 39 | +- `ArcadeDBError`: If the JVM is already started with a different configuration, the bundled runtime is missing, or JPype cannot start the JVM |
| 40 | + |
| 41 | +**Notes:** |
| 42 | + |
| 43 | +- The bundled JRE is always used; no external Java installation is required |
| 44 | +- The module injects required defaults such as `jdk.incubator.vector`, UTF-8 file encoding, and required `--add-opens` flags if they are not already provided |
| 45 | +- `ARCADEDB_JVM_ARGS` remains supported as an environment fallback, but in-code configuration is preferred |
| 46 | + |
| 47 | +## shutdown_jvm |
| 48 | + |
| 49 | +```python |
| 50 | +from arcadedb_embedded.jvm import shutdown_jvm |
| 51 | + |
| 52 | +shutdown_jvm() |
| 53 | +``` |
| 54 | + |
| 55 | +Shuts down the JVM if it is running in the current process. |
| 56 | + |
| 57 | +!!! note |
| 58 | + Most application code does not need to call this directly. Normal database and |
| 59 | + server usage should focus on proper object cleanup; use this helper mainly in |
| 60 | + test harnesses or short-lived tooling. |
| 61 | + |
| 62 | +## get_jar_path |
| 63 | + |
| 64 | +```python |
| 65 | +from arcadedb_embedded.jvm import get_jar_path |
| 66 | + |
| 67 | +jar_dir = get_jar_path() |
| 68 | +``` |
| 69 | + |
| 70 | +Returns the directory containing the bundled ArcadeDB JAR files. |
| 71 | + |
| 72 | +## get_bundled_jre_lib_path |
| 73 | + |
| 74 | +```python |
| 75 | +from arcadedb_embedded.jvm import get_bundled_jre_lib_path |
| 76 | + |
| 77 | +jvm_lib = get_bundled_jre_lib_path() |
| 78 | +``` |
| 79 | + |
| 80 | +Returns the platform-specific JVM library path inside the bundled runtime: |
| 81 | + |
| 82 | +- Linux: `lib/server/libjvm.so` |
| 83 | +- macOS: `lib/server/libjvm.dylib` |
| 84 | +- Windows: `bin/server/jvm.dll` |
| 85 | + |
| 86 | +Raises `ArcadeDBError` if the bundled runtime is missing or incomplete. |
| 87 | + |
| 88 | +## Recommended Pattern |
| 89 | + |
| 90 | +```python |
| 91 | +from arcadedb_embedded.jvm import start_jvm |
| 92 | +import arcadedb_embedded as arcadedb |
| 93 | + |
| 94 | +start_jvm(heap_size="8g", jvm_args="-XX:MaxDirectMemorySize=8g") |
| 95 | + |
| 96 | +with arcadedb.create_database("./db") as db: |
| 97 | + row = db.query("sql", "SELECT 1 AS ok").one() |
| 98 | + assert row.get("ok") == 1 |
| 99 | +``` |
0 commit comments