Поток [#39,PostgreSQL-JDBC-Cleaner,5,server.Server] был прерван, но все еще активен после ожидания не менее 15 000 мс.JAVA

Программисты JAVA общаются здесь
Anonymous
Поток [#39,PostgreSQL-JDBC-Cleaner,5,server.Server] был прерван, но все еще активен после ожидания не менее 15 000 мс.

Сообщение Anonymous »

Я пытаюсь запустить сервер приложения, но когда я запускаю его из maven, они работают примерно 30 секунд или около того, а затем сервер выдает следующую ошибку:

Код: Выделить всё

[WARNING] thread Thread[#39,PostgreSQL-JDBC-Cleaner,5,server.Server] was interrupted but is still alive after waiting at least 15000msecs [WARNING] thread Thread[#39,PostgreSQL-JDBC-Cleaner,5,server.Server] will linger despite being asked to die via interruption [WARNING] NOTE: 1 thread(s) did not finish despite being asked to via interruption. This is not a problem with exec:java, it is a problem with the running code.  Although not serious, it should be remedied.
Но если я запущу jar-сервер, он не остановится, пока я его не выключу.
Проблема в том, что когда я пытаюсь подключиться к клиентской стороне, пока сервер включен, я могу использовать методы для запуска запросов к базе данных postgres, но когда сервер выключается, когда я пытаюсь вызвать методы, он возвращает ошибку, потому что сервер отключился , это происходит только тогда, когда я запускаю сервер из maven, но когда я запускаю его из cmd, этого не происходит, и я могу нормально запускать методы.
Основным классом является сервер:< /p>

Код: Выделить всё

public class Server extends UnicastRemoteObject implements GenericRemoteInterface{

private final static long serialVersionUID = 10L;

/**
* The database object.
*/
private DBAdapterDatabase db;

/**
* The port number for the server.
*/
private final static int PORT=2020; //! DO NOT CHANGE

/**
* The constructor of the server.
* @param port
* @param db
* @throws IOException
*/
protected Server(int port, DBAdapterDatabase db) throws IOException {
super(port);
this.db=db;
}

/**
* The main method of the server.
* @param args not used in this application
* @throws RemoteException
* @throws IllegalArgumentException
*/
public static void main(String[] args) throws RemoteException, IllegalArgumentException {
try {
// Read the arguments
CliParser.parseCli(args);

//--- To set the hostname of the server (needed for RMI)
String ip = null;
if(!CliParser.isLocal()) { //If it's not local, use the external IP
// Code thanks to https://stackoverflow.com/questions/2939218/getting-the-external-ip-address-in-java
URL whatismyip = new URL("http://checkip.amazonaws.com");
BufferedReader in = new BufferedReader(new InputStreamReader(
whatismyip.openStream()));
ip = in.readLine();
if(ip==null || ip.isEmpty()){
logError("IP not found, exiting...");
System.exit(-1);
}
System.setProperty("java.rmi.server.hostname", ip);
logInitialMessage("Application starting on external IP: " + ip + "...");
}else{
logInitialMessage("Application starting on internal IP...");
}
//---

// Show environment variables on startup
logEnvironmentVariables();

DBAdapterDatabase db=new DBAdapterDatabase();
try {
db.init();
}catch (SQLException e){
logError("DATABASE ERROR: "+e.getMessage());
System.exit(-1);
}

log("---------------------------------------------------");
log("                       SERVER (V."+serialVersionUID+")                       ");
log("---------------------------------------------------");

// To set up the database pool
ConnectionInstance.setUpDBPool();

// To create the server
Server server = new Server(PORT, null);

// To start the registry
Registry registry = LocateRegistry.createRegistry(PORT);
if(CliParser.isLocal())
log("RMI registry running on port: " + PORT + " on the local host");
else
log("RMI registry running on port: " + PORT + " with IP: "  + ip);

registry.bind("server",  server);

}

/**
* The method to get the connection.
* @param userID
* @param pass
* @return
* @throws RemoteException
*/
public ConnectionInstanceInterface getConnection(String userID, String pass) throws RemoteException {
User user1=new User();
//ricerca da db
return new ConnectionInstance(user1);
}

/**
* The method to get the connection.
* @return
* @throws RemoteException
*/
public ConnectionInstanceInterface getConnection() throws RemoteException {
return new ConnectionInstance();
}

/**
* Utility method to log environment variables on startup.
* @throws UnknownHostException
*/
private static void logEnvironmentVariables() throws UnknownHostException {
log("------------------ENVIRONMENT VARIABLES--------------------");
log("POSTGRES_ADMIN_USER: "+ CliParser.getAdminUser());
log("POSTGRES_ADMIN_PASSWORD: " + CliParser.getAdminPassword());
InetAddress sqlAddress= InetAddress.getByName(CliParser.getPostgresURL());
String address = sqlAddress.getHostAddress().replace("/", "");
log("POSTGRES_URL: "+ CliParser.getPostgresURL() + " WITH IP: " + address);
log("SERVER_VERSION: " + serialVersionUID);
log("POSTGRES_MAX_CONNECTIONS: " + CliParser.getMaxConnections() + "  [1020]");
log("POSTGRES_SHARED_BUFFER: " + CliParser.getSharedBufferSize() + "  [128MB]");
log("SERVER_MAX_DB_CONNECTIONS: " + CliParser.getMaxDBConnections() + "  [1000]");
log("----------------------------------------------------------");
}

}
Полный вывод при работе с maven:

Код: Выделить всё

[INFO] Scanning for projects...
[INFO]
[INFO] -----------------------< railwai.Server:Server >------------------------
[INFO] Building Server 1.0-SNAPSHOT
[INFO]   from pom.xml
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- resources:3.3.1:resources (default-resources) @ Server ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 0 resource from src\main\resources to target\classes
[INFO]
[INFO] --- compiler:3.10.1:compile (default-compile) @ Server ---
[INFO] Changes detected - recompiling the module!
[WARNING] File encoding has not been set, using platform encoding UTF-8, i.e. build is platform dependent!
[INFO]
[INFO] --- exec:3.1.0:java (default-cli) @ Server ---

[INFO] server.Server.logEnvironmentVariables:  ------------------ENVIRONMENT VARIABLES--------------------
[INFO] server.Server.logEnvironmentVariables:  POSTGRES_URL: localhost WITH IP: 127.0.0.1
[INFO] server.Server.logEnvironmentVariables:  SERVER_VERSION: 10
[INFO] server.Server.logEnvironmentVariables:  POSTGRES_MAX_CONNECTIONS: 115  [1020]
[INFO] server.Server.logEnvironmentVariables:  POSTGRES_SHARED_BUFFER: 128MB  [128MB]
[INFO] server.Server.logEnvironmentVariables:  SERVER_MAX_DB_CONNECTIONS: 5  [1000]
[INFO] server.Server.logEnvironmentVariables:  ----------------------------------------------------------
[INFO] database.DBAdapterDatabase.init:  ---------------------------------------------------
[INFO] database.DBAdapterDatabase.init:                        DATABASE
[INFO] database.DBAdapterDatabase.init:  ---------------------------------------------------
[INFO] database.DBAdapterDatabase.init:  Integrity check of the database
[INFO] database.DBAdapterDatabase.init:  The database has already been initialized, proceed to start up the server
[INFO] database.DBAdapterDatabase.init:  random generato
[INFO] database.DBAdapterDatabase.init:  Performing database cache (Expect poor performance for the first few minutes)
[INFO] server.Server.main:  ---------------------------------------------------
[INFO] database.DBAdapterDatabase.lambda$init$0:  Caching the database
[INFO] server.Server.main:                         SERVER (V.10)
[INFO] server.Server.main:  ---------------------------------------------------
[INFO] database.DBAdapterDatabase.cacheDatabase: Database cached successfully
[INFO] server.DBPool$1.run:  Creating DB connections in background.
[INFO] server.DBPool$1.run:  DB connections created.  The server is ready to accept connections.
[WARNING] thread Thread[#39,PostgreSQL-JDBC-Cleaner,5,server.Server] was interrupted but is still alive after waiting at least 15000msecs
[WARNING] thread Thread[#39,PostgreSQL-JDBC-Cleaner,5,server.Server] will linger despite being asked to die via interruption
[WARNING] NOTE: 1 thread(s) did not finish despite being asked to via interruption. This is not a problem with exec:java, it is a problem with the running code.  Although not serious, it should be remedied.
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  20.072 s
[INFO] Finished at: 2024-06-30T14:25:26+02:00
[INFO] ------------------------------------------------------------------------

Process finished with exit code 0
Пока файл pom:

Код: Выделить всё

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4.0.0

railwai.Server
Server
1.0-SNAPSHOT


17
17
5.9.2
21




org.apache.commons
commons-dbcp2
2.9.0


org.postgresql
postgresql
42.6.0


commons-cli
commons-cli
1.3.1


org.junit.jupiter
junit-jupiter-api
${junit.version}
test


org.junit.jupiter
junit-jupiter-engine
${junit.version}
test








org.apache.maven.plugins
maven-shade-plugin
3.2.1


package

shade


true


server.Server








org.apache.maven.plugins
maven-compiler-plugin
3.10.1

${javaTarget.version}
${javaTarget.version}
${javaTarget.version}





org.apache.maven.plugins
maven-javadoc-plugin
3.4.1






org.apache.maven.plugins
maven-site-plugin
3.7.1



org.apache.maven.plugins
maven-surefire-plugin
2.22.1






И команда, используемая при его запуске:

Код: Выделить всё

compile exec:java -Dexec.mainClass=server.Server

Код: Выделить всё

Whit this environment variables:

POSTGRES_ADMIN_USER=postgres;POSTGRES_URL=localhost;POSTGRES_MAX_CONNECTIONS=115;SERVER_MAX_DB_CONNECTIONS=5;POSTGRES_SHARED_BUFFER=128MB
Кто-нибудь знает, как я могу решить эту проблему?
Заранее всем спасибо

Подробнее здесь: https://stackoverflow.com/questions/786 ... t-is-still

Вернуться в «JAVA»