Tuning Java Pool after getting ORA-04031
With SGA_TARGET set and JAVA_POOL_SIZE=0 it you are at least using Automatic Shared Memory Management, so the Java Pool is already self-tuning. You can specify a JAVA_POOL_SIZE value that will become the minimum pool size and Oracle may choose to tune it higher if necessary. Changing the JAVA_POOL_SIZE will require a restart of the database. You may need to increase the SGA_TARGET value as well, as increasing the default JAVA_POOL_SIZE will take memory away from other SGA pools.

https://docs.oracle.com/en/database/oracle/oracle-database/12.2/refrn/JAVA_POOL_SIZE.html#GUID-F24C4770-0B7C-42BD-9AAD-0EC1E92A90F6