Skip to content

Commit

Permalink
use port zero to allow OS to determine best free port to use (#2698)
Browse files Browse the repository at this point in the history
  • Loading branch information
rafaelbey authored Mar 14, 2024
1 parent 44a7171 commit 0fecc5f
Showing 1 changed file with 3 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,17 @@

public class H2LocalServer
{
private static final H2LocalServer INSTANCE = new H2LocalServer(DynamicPortGenerator.generatePort());
private static final H2LocalServer INSTANCE = new H2LocalServer();
private final int port;

private H2LocalServer(int port)
private H2LocalServer()
{
this.port = port;
try
{
// We can create only one instance of the server as the databases are anyway shared in the process (VM)
// The important part is to have an empty name in 'this.buildDataSource("127.0.0.1", localH2Port, "", null)'
// It ensure the database creation is 'private' to the connection.
AlloyH2Server.startServer(port);
this.port = AlloyH2Server.startServer(0).getPort();
}
catch (SQLException e)
{
Expand Down

0 comments on commit 0fecc5f

Please sign in to comment.