# Java and memory settings

The server is a Java program. Two things about Java are yours to decide: which Java it runs on, and how much memory it may use. This page says where both are set on each system.

## Which Java

Java 21 at least; 25 or later is recommended. See [Requirements](Requirements.md#java).

You do not have to install it: with no Java 21 or later on the computer, CrushMFT downloads Eclipse Temurin at its first start and keeps it up to date by itself. See [CrushMFT's own Java](Java-Updates.md).

### Where the server looks

| System | In this order |
|---|---|
| Windows | `java=` in the service's conf file; the folder `Java` in the CrushMFT folder; `JAVA_HOME`; `JAVA_PATH`; the system's `PATH` |
| macOS, the app | `java=` in `CrushMFT.conf`; the folder `Java` in the CrushMFT folder; `JAVA_HOME`; the newest Java installed on the Mac |
| Linux | `JAVA` in `crushmft_init.sh`. Left at `java`, that means: the folder `Java` in the CrushMFT folder if there is one, else the system's Java. |

With none of these giving a Java 21 or later, the start downloads one into the folder `Java`.

### A Java of its own

There are two kinds of `Java` folder in the CrushMFT folder:

- **The one CrushMFT downloaded.** CrushMFT keeps it up to date: [CrushMFT's own Java](Java-Updates.md).
- **One you unpacked there yourself.** Nothing else on the machine changes it, and neither does CrushMFT. You decide when it is updated, and updating it is replacing that folder while the server is stopped.

A Java installed for the whole system is updated by the system. CrushMFT uses it and leaves it alone.

Whichever it is: keep Java current. Java's updates are security updates.

### Which Java is it running on?

The **About** section of Server Admin shows the Java version. On Linux, `./crushmft_init.sh info` shows which Java the script would start.

## Memory

The server may use memory up to a limit, the **heap**. Above that it cannot grow, whatever the machine has free. How much to give is in [Performance](Ops-Performance.md#memory); in short: 1 GB for a small server, 2 to 4 GB for a busy one, and never more than three quarters of the machine's memory.

### Where it is set

| Where | How |
|---|---|
| **the admin pages** | **Set max server memory** on the Dashboard and the Overview of Server Admin: a number of megabytes. "Max server memory set to … MB." It writes the setting below for you. |
| **the control panel**, Windows and macOS | the **Memory** card: megabytes, or a share of the machine's memory |
| **Windows**, by hand | `memory=` in `service\CrushMFTService.conf`: `2048`, or `50%` |
| **macOS**, by hand | `memory=` in `CrushMFT.conf` in the CrushMFT folder, in the same two forms |
| **Linux**, by hand | the first option of `JAVA_OPTS` in `crushmft_init.sh`: `-Xmx2g`, `-Xmx2048m`. Keep it first: the admin pages rewrite that number. |

A share, such as `50%`, is worked out at each start from the memory the machine has then. It suits machines whose memory may be changed, such as virtual ones.

The new value counts from the **next start** of the server.

### Is it enough?

The Dashboard shows the memory in use against the most allowed. A server that stays near the top is short: logins and listings slow down first. The alert **Low Memory** can tell you before users do: [Alerts](Alerts.md).

## Other Java options

Options for Java itself go where the memory is set:

| System | Where |
|---|---|
| Windows | `java_params=` in `service\CrushMFTService.conf` |
| macOS | `java_params=` in `CrushMFT.conf` |
| Linux | `JAVA_OPTS` in `crushmft_init.sh`, after the memory |

The ones you may meet:

| Option | For |
|---|---|
| `-Dcrushmft.fips=true` | [FIPS mode](FIPS-Mode.md) |
| `-Djava.net.preferIPv4Stack=true` | a machine where IPv6 gets in the way |
| `-Dhttps.proxyHost=…`, `-Dhttps.proxyPort=…` | Java's own way of naming a proxy for outgoing HTTPS |
| `-XX:-UseBASE64Intrinsics` | in the Linux script as delivered: it turns off one of Java's shortcuts. Leave it. |

Leave the options that the download comes with as they are. Add others only for a reason, one at a time: a wrong option can keep Java from starting. If it does not start after a change, take the change out again.

## Certificates Java trusts

When the server connects out, to a mail server, a directory, another file server, it checks the other side's certificate against the authorities Java trusts. A certificate from your organisation's own authority is not among them.

Add your authority's certificate to the trust store of the Java the server runs on, with Java's `keytool`:

```bash
keytool -importcert -cacerts -alias example-ca -file example-ca.cer
```

and restart the server. When CrushMFT updates its own Java, it carries the certificates you added over to the new one, and leaves out the ones you removed. After replacing a Java folder yourself, do it again.

Earlier versions of Java needed extra files for strong encryption, the "JCE policy files". Current Java has strong encryption built in, and nothing has to be installed.

## Things to know

- **The job engine** has memory of its own, apart from the server's: [Job engines](Jobs-Engines.md).
- **Memory outside the heap** is used as well: for threads and network buffers. A machine should have room beyond the heap.
- **A start that fails after a change** is nearly always the change. The service's log (Windows: `service\wrapper.log`; macOS: `CrushMFT_launcher.log`; Linux: the journal or `nohup.out`) says what Java complained about.

## Not tried for this page

The places and forms of the settings are read from the start script, the launchers' designs and the admin pages' code. Setting the memory from the admin pages was not tried on a test server for this page.
