我是使用Java的MongoDB的新手,在tomcat的控制台中重复运行我的webapp时获取以下日志。我使用以下代码使用java访问MongoDB。我在 TimerTask 中编写了mongodb连接代码,并在TimerTask的run方法中插入了一个文档,我不知道这个错误是因为mongodb还是别的。
class RequestTask extends TimerTask {
MongoClientURI mongoClientURI = new MongoClientURI("mongodb://" + dbURL);
MongoClient mongoClient = new MongoClient(mongoClientURI);
/*
* To connect database, specify the database name, if the
* database doesn't exist then MongoDB creates it automatically.
*/
MongoDatabase mongoDatabase = mongoClient.getDatabase(dbName);
// System.out.println("Connected to database successfully");
MongoCollection<Document> mongoCollection = mongoDatabase.getCollection(collectionName);
public void run() {
try {
// Other code
mongoCollection.insertOne(jsonDocument);
// Other code
} catch (Exception e) {
System.err.println(e.getClass().getName() + "During Collection Insert : " + e.getMessage());
}
}
}
创建上述RequestTask的实例并使用scheduledExecutorService的scheduleAtFixedRate方法安排它
timerTask = new RequestTask();
timer = scheduledExecutorService.scheduleAtFixedRate(timerTask, 0,
pollingInterval.getPollingInterval(), TimeUnit.SECONDS);
错误在Tomcat控制台中记录为:
Feb 22, 2017 12:33:45 PM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["http-nio-8090"]
Feb 22, 2017 12:33:45 PM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["ajp-nio-8009"]
Feb 22, 2017 12:33:45 PM org.apache.catalina.startup.Catalina start
INFO: Server startup in 4508 ms
Feb 22, 2017 12:33:55 PM org.apache.catalina.core.StandardContext reload
INFO: Reloading Context with name [/qxpsmonitor] has started
Feb 22, 2017 12:33:55 PM org.apache.catalina.loader.WebappClassLoaderBase clearReferencesThreads
WARNING: The web application [qxpsmonitor] appears to have started a thread named [cluster-ClusterId{value='58ad37d09ad1689fa0249f07', description='null'}-null:27017] but has failed to stop it. This is very likely to create a memory leak. Stack trace of thread:
java.net.Inet6AddressImpl.lookupAllHostAddr(Native Method)
java.net.InetAddress$1.lookupAllHostAddr(InetAddress.java:901)
java.net.InetAddress.getAddressesFromNameService(InetAddress.java:1295)
java.net.InetAddress.getAllByName0(InetAddress.java:1248)
java.net.InetAddress.getAllByName(InetAddress.java:1164)
java.net.InetAddress.getAllByName(InetAddress.java:1098)
java.net.InetAddress.getByName(InetAddress.java:1048)
com.mongodb.ServerAddress.getSocketAddress(ServerAddress.java:186)
com.mongodb.connection.SocketStreamHelper.initialize(SocketStreamHelper.java:57)
com.mongodb.connection.SocketStream.open(SocketStream.java:58)
com.mongodb.connection.InternalStreamConnection.open(InternalStreamConnection.java:115)
com.mongodb.connection.DefaultServerMonitor$ServerMonitorRunnable.run(DefaultServerMonitor.java:113)
java.lang.Thread.run(Thread.java:745)
Feb 22, 2017 12:33:55 PM org.apache.catalina.loader.WebappClassLoaderBase clearReferencesThreads
WARNING: The web application [qxpsmonitor] appears to have started a thread named [pool-2-thread-1] but has failed to stop it. This is very likely to create a memory leak. Stack trace of thread:
sun.misc.Unsafe.park(Native Method)
java.util.concurrent.locks.LockSupport.parkNanos(LockSupport.java:226)
java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.awaitNanos(AbstractQueuedSynchronizer.java:2082)
java.util.concurrent.ScheduledThreadPoolExecutor$DelayedWorkQueue.take(ScheduledThreadPoolExecutor.java:1090)
java.util.concurrent.ScheduledThreadPoolExecutor$DelayedWorkQueue.take(ScheduledThreadPoolExecutor.java:807)
java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:1068)
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1130)
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
java.lang.Thread.run(Thread.java:745)
Feb 22, 2017 12:33:56 PM org.apache.jasper.servlet.TldScanner scanJars
INFO: At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.