Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The quietlySleep (30) in the PoolElementCreator class is not a good design #2233

Closed
leviYX opened this issue Aug 29, 2024 · 2 comments
Closed

Comments

@leviYX
Copy link

leviYX commented Aug 29, 2024

When I read the source code, I executed connectionBag. add (poolEntry) in the call method of PoolEntry Creator; Afterwards, it will sleep the current thread for 30 seconds and quietsleep (30);
I think this is not appropriate. We should expose this parameter to HikariConfig and default it to 30 in the constructor. The user can decide the sleep time themselves through the set method. The code is as follows:

step1:Add the quietlySleepTime property to the HikariConfig class,the code is as follows
`
public class HikariConfig implements HikariConfigMXBean

private static final long QUIETLY_SLEEP_TIME = 30L;
private long quietlySleepTime;
public HikariConfig()
{
  ......
  quietlySleepTime = QUIETLY_SLEEP_TIME;

  ......
}

public void setQuietlySleepTime(long quietlySleepTime) {
  this.quietlySleepTime = quietlySleepTime;

}

}
`

step2:Simply reference this property in the call method of PoolElementCreator,the code is as follows

`
private final class PoolEntryCreator implements Callable
{

@Override
public Boolean call()
{
   var backoffMs = 10L;
   var added = false;
   try {
	  while (shouldContinueCreating()) {
	     final var poolEntry = createPoolEntry();
	     if (poolEntry != null) {
		    ......
		    quietlySleep(config.getQuietlySleepTime());
		    break;
	     } 
	  }
   }
   finally {
	  if (added && loggingPrefix != null)
	     logPoolState(loggingPrefix);
	  else if (!added)
	     logPoolState("Connection not added, ");
   }

   // Pool is suspended, shutdown, or at max size
   return Boolean.FALSE;
}

}

`
step3:user can config this param in HikariConfig

`
HikariConfig hikariConfig = new HikariConfig();
......
hikariConfig.setQuietlySleepTime(60);
......
return new HikariDataSource(hikariConfig);

`

@quaff
Copy link
Contributor

quaff commented Sep 6, 2024

You should submit an PR instead of posting code snippet.

@brettwooldridge
Copy link
Owner

What are you talking about? The code sleeps for 30 milliseconds, not 30 seconds.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants