我运行我的Web应用程序时收到此消息.它运行正常,但我在关机期间收到此消息.
严重:Web应用程序注册了JBDC驱动程序[oracle.jdbc.driver.OracleDriver],但在Web应用程序停止时无法注销它.为防止内存泄漏,JDBC驱动程序已被强制取消注册.
任何帮助赞赏.
在Spring Web应用程序中,我有几个DAO和服务层bean.一个服务层bean具有带注释的@Async/@Scheduled方法.这些方法依赖于其他(自动装配的)bean.我在XML中配置了两个线程池:
<bean id="taskExecutor" class="org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor">
<property name="corePoolSize" value="2" />
<property name="maxPoolSize" value="5" />
<property name="queueCapacity" value="5" />
<property name="waitForTasksToCompleteOnShutdown" value="true" />
<property name="rejectedExecutionHandler">
<bean class="java.util.concurrent.ThreadPoolExecutor$CallerRunsPolicy"/>
</property>
</bean>
<bean id="taskScheduler" class="org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler">
<property name="poolSize" value="10" />
<property name="waitForTasksToCompleteOnShutdown" value="true" />
<property name="rejectedExecutionHandler">
<bean class="java.util.concurrent.ThreadPoolExecutor$CallerRunsPolicy"/>
</property>
</bean>
<task:annotation-driven executor="taskExecutor" scheduler="taskScheduler"/>
Run Code Online (Sandbox Code Playgroud)
一切都按预期工作.我的问题是我无法完全关闭任务池.任务在数据库和文件系统上运行.当我停止Web应用程序时,它需要一些时间才能停止.这表明该waitForTasksToCompleteOnShutdown
物业有效.但是,我在日志中得到IllegalStateExceptions,表明某些bean已经被销毁但是一些工作任务线程仍在执行,并且它们因为依赖项被破坏而失败.
有一个JIRA问题可能是相关的:SPR-5387
我的问题是:有没有办法告诉Spring最后初始化任务执行程序/调度程序bean还是有办法告诉Spring先破坏它们吗?
我的理解是,销毁是以颠倒的初始顺序进行的.因此,最后初始化的bean将首先被销毁.如果首先销毁线程池bean,则所有当前正在执行的任务都将完成,并且仍然可以访问依赖bean.
我还尝试在引用我的服务bean的线程池上使用depends-on属性,该服务bean具有@Async和@Scheduled注释.好像它们从未执行过,我没有得到上下文初始化错误.我假设带注释的服务bean在某种程度上需要首先初始化这些线程池,如果我使用依赖,我会颠倒顺序并使它们不起作用.
当我尝试在Java 8上停止tomcat8时,我收到一些内存泄漏错误:
org.apache.catalina.loader.WebappClassLoaderBase.clearReferencesThreads The web application [ROOT] appears to have started a thread named [Abandoned connection cleanup thread] but has failed to stop it. This is very likely to create a memory leak. Stack trace of thread:
java.lang.Object.wait(Native Method)
java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:142)
com.mysql.jdbc.AbandonedConnectionCleanupThread.run(AbandonedConnectionCleanupThread.java:40)
23-Jan-2015 08:18:10.202 WARNING [localhost-startStop-2] org.apache.catalina.loader.WebappClassLoaderBase.clearReferencesThreads The web application [ROOT] appears to have started a thread named [pool-5-thread-1] but has failed to stop it. This is very likely to create a memory leak. Stack trace of thread
23-Jan-2015 08:18:10.205 SEVERE …
Run Code Online (Sandbox Code Playgroud) 在tomcat容器中开发基于SPRING的调度程序期间,我总是在取消部署webapp或shutdown服务器时获得此logoutput:
Apr 28, 2010 4:21:33 PM org.apache.catalina.core.StandardService stop
INFO: Stopping service Catalina
Apr 28, 2010 4:21:33 PM org.apache.catalina.loader.WebappClassLoader clearReferencesThreads
SEVERE: A web application appears to have started a thread named [org.springframework.scheduling.quartz.SchedulerFactoryBean#0_Worker-1] but has failed to stop it. This is very likely to create a memory leak.
Apr 28, 2010 4:21:33 PM org.apache.catalina.loader.WebappClassLoader clearReferencesThreads
SEVERE: A web application appears to have started a thread named [org.springframework.scheduling.quartz.SchedulerFactoryBean#0_Worker-2] but has failed to stop it. This is very likely to create a memory leak. …
Run Code Online (Sandbox Code Playgroud) 我想向特定客户发送通知.
例如用户名用户
@Configuration
@EnableWebSocketMessageBroker
public class WebSocketConfiguration extends
AbstractWebSocketMessageBrokerConfigurer {
@Override
public void registerStompEndpoints(StompEndpointRegistry stompEndpointRegistry) {
stompEndpointRegistry.addEndpoint("/socket")
.setAllowedOrigins("*")
.withSockJS();
}
@Override
public void configureMessageBroker(MessageBrokerRegistry registry) {
registry.enableSimpleBroker("/topic", "/queue");
registry.setApplicationDestinationPrefixes("/app");
}
Run Code Online (Sandbox Code Playgroud)
调节器
@GetMapping("/notify")
public String getNotification(Principal principal) {
String username = "user";
notifications.increment();
logger.info("counter" + notifications.getCount() + "" + principal.getName());
// logger.info("usersend:"+sha.getUser().getName()) ; //user
template.convertAndSendToUser(principal.getName(), "queue/notification", notifications);
return "Notifications successfully sent to Angular !";
}
Run Code Online (Sandbox Code Playgroud)
客户端
角度服务
connect() {
let socket = new SockJs(`api/socket`);
let stompClient = Stomp.over(socket);
return stompClient;
} …
Run Code Online (Sandbox Code Playgroud) 我在jboss 4.0.5上使用目前最新的石英1.8.3.quartz作业是持久的并保存到本地数据库中.当我在执行石英调度程序对象上调用shutdown或standby方法时,调度程序仍继续执行作业,只有作业状态为空且执行失败.
我希望(至少根据石英API文档)当我关闭或使调度程序处于待机状态时,之前调度到数据库中的作业将不会被执行.
如果在调度程序上调用shutdown或standby不是实现它的方法,那是什么?
这些工作不只是完成执行,而是继续触发计划工作.
以下是其他信息:
public class QuartzNotificationsSchedulerBean implements NotificationsScheduler, ServletContextAware {
...
public String scheduleNotification(Notification notification) {
// Schedule the job with the trigger
try {
// Define job instance
String groupName = this.createNotificationGroupName(notification);
String triggerName = this.createNoficationTriggerName(notification);
String jobName = this.createNoficationJobName(notification);
JobDetail job = new JobDetail(jobName, groupName , ScheduledNotificationJob.class);
JobDataMap jobDataMap = new JobDataMap();
jobDataMap.putAll(notification.getContext());
job.setJobDataMap(jobDataMap);
Calendar notificationTime = notification.getTime();
Trigger trigger = new SimpleTrigger(triggerName, groupName , notificationTime.getTime());
scheduler.scheduleJob(job, trigger);
return trigger.getName();
} catch (SchedulerException e) { …
Run Code Online (Sandbox Code Playgroud) java ×6
spring ×3
tomcat ×3
jboss ×1
jdbc ×1
memory-leaks ×1
spring-boot ×1
stomp ×1
threadpool ×1