Forums Register Login

how to set eclipselink reconnect atampts to one

+Pie Number of slices to send: Send
how to set eclipselink reconnect atampts to one .because when swing code executes a query if database is down then the gui will hang or freeze for some times its not a good idea to do.
are there any other ways to throw the exception and inside try catch just show it to user?

i went trougheclipselink sourc code,
this is a snapshot from .
class DatabaseLogin extends DatasourceLogin{

public DatabaseLogin(DatabasePlatform databasePlatform) {
super(databasePlatform);
this.useDefaultDriverConnect();
this.delayBetweenConnectionAttempts = 5000;
this.queryRetryAttemptCount = 3;
this.connectionHealthValidatedOnError = true;
}
}



this is a snapshot from AbstractSession .java


protected void basicBeginTransaction(int retryCount, Accessor accessor) throws DatabaseException {
try {
accessor.beginTransaction(this);
} catch (DatabaseException databaseException) {
// Retry if the failure was communication based? (i.e. timeout, database down, can no longer ping)
if ((!getDatasourceLogin().shouldUseExternalTransactionController()) && databaseException.isCommunicationFailure()) {
DatabaseException exceptionToThrow = databaseException;
log(SessionLog.INFO, "communication_failure_attempting_query_retry", (Object[])null, null);
// Attempt to reconnect connection.
while (retryCount < getLogin().getQueryRetryAttemptCount()) {
try {
// if database session then re-establish
// connection
// else the session will just get a new
// connection from the pool
databaseException.getAccessor().reestablishConnection(this);
break;
} catch (DatabaseException ex) {
// failed to get connection because of
// database error.
++retryCount;
try {
// Give the failover time to recover.
Thread.currentThread().sleep(getLogin().getDelayBetweenConnectionAttempts());
log(SessionLog.INFO, "communication_failure_attempting_begintransaction_retry", (Object[])null, null);
} catch (InterruptedException intEx) {
break;
}
}
}
//retry
if (retryCount <= getLogin().getQueryRetryAttemptCount()) {
try {
// attempt to reconnect for a certain number of times.
// servers may take some time to recover.
++retryCount;
try {
//passing the retry count will prevent a runaway retry where
// we can acquire connections but are unable to execute any queries
if (retryCount > 1){
// We are retrying more than once lets wait to give connection time to restart.
//Give the failover time to recover.
Thread.currentThread().sleep(getLogin().getDelayBetweenConnectionAttempts());
}
basicBeginTransaction(retryCount, accessor);
return;
} catch (DatabaseException ex){
//replace original exception with last exception thrown
//this exception could be a data based exception as opposed
//to a connection exception that needs to go back to the customer.
exceptionToThrow = ex;
}
} catch (InterruptedException ex) {
//Ignore interrupted exception.
}
}
handleException(exceptionToThrow);
} else {
handleException(databaseException);
}
} catch (RuntimeException exception) {
handleException(exception);
}
}
+Pie Number of slices to send: Send
This can be configured on your Session's DatabaseLogin (you can configure the Session using a SessionCustomizer in JPA).


login.setQueryRetryAttemptCount(0);

you may also try,

login.setConnectionHealthValidatedOnError(false)
My honeysuckle is blooming this year! Now to fertilize this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 2763 times.
Similar Threads
stale jdbc Connection
rmi: Connection reset
Exception Base classes
how to detect connection status
Resultset
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 19, 2024 02:29:53.