论坛首页 入门技术论坛

用java写了一个定时器 为什么运行两天后就突然停了

浏览 24196 次
该帖已经被评为新手帖
作者 正文
   发表时间:2012-10-31  
apopo 写道
風一樣的男子 写道
sziitjiang 写道
hekuilove 写道
Rong_it 写道
風一樣的男子 写道
这格式不想看

me too 哈哈

me too.

me too. 用Eclipse的格式化代码控飘过,哈哈


团队协同开发禁止随意格式化代码
只允许选定自己修改的代码进行格式化

公司应该提供统一的格式化模板


不管是SVN、git、cvs还是啥
你已格式化,别人同步的时候就有可能冲突了
0 请登录后投票
   发表时间:2012-10-31  
为什么不用Executors.newScheduledThreadPool,使用Timer在抛出异常时会出现未知的情况。Timer线程并不捕获异常,所以TimerTask抛出的未检查的异常会终止timer线程。它错误的认为整个Timer都被取消了。
0 请登录后投票
   发表时间:2012-10-31  
websphere6.0下部署war包,异常javax.naming.NameNotFoundException: Namenotfound java:
xp 环境下 websphere6.0下部署war包,异常javax.naming.NameNotFoundException: Namenotfound java: 
web.xml配置:

<resource-ref id="ResourceRef_1">
<description>DB Connection</description>
<res-ref-name>oscdb</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>

spring.xml 配置

<bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
  <property name="jndiName">
  <value>oscdb</value>
  </property> 
  <property name="resourceRef"> 
  <value>true</value> 
  </property> 
  </bean>
was控制台jndi配置已测试通过

那位大侠有遇到此类问题,请一起讨论一下,谢谢!!!
异常日志如下:
************* End Display Current Environment *************
[12-10-31 14:56:00:812 CST] 0000007f javaURLContex E NMSV0310E: 由于服务器运行时无法将“java:”名称上的 JNDI 操作的线程与任何 J2EE 应用程序组件相关联,该操作无法完成。当使用“java:”名称的 JNDI 客户机不在服务器应用程序请求的线程中执行时,就会出现这种情况。确保 J2EE 应用程序不在静态代码块或该 J2EE 应用程序创建的线程中对“java:”名称执行 JNDI 操作。此类代码不必在服务器应用程序请求的线程中运行,因此不受“java:”名称上的 JNDI 操作支持。异常堆栈跟踪:
javax.naming.ConfigurationException [Root exception is javax.naming.NameNotFoundException: Name not found in context "java:".]
at com.ibm.ws.naming.java.javaURLContextImpl.throwConfigurationExceptionWithDefaultJavaNS(javaURLContextImpl.java:411)

at com.ibm.ws.naming.java.javaURLContextImpl.lookup(javaURLContextImpl.java:388)
at com.ibm.ws.naming.java.javaURLContextRoot.lookup(javaURLContextRoot.java:201)
at com.ibm.ws.naming.java.javaURLContextRoot.lookup(javaURLContextRoot.java:142)
at javax.naming.InitialContext.lookup(InitialContext.java:363)
at com.paraview.jar.core.tools.ServiceLocator.getInitialContext(ServiceLocator.java:182)
at com.paraview.jar.core.tools.ServiceLocator.<init>(ServiceLocator.java:57)
at com.paraview.jar.core.tools.ServiceLocator.getInstance(ServiceLocator.java:73)
at com.paraview.jar.core.tools.ConnDefImpl.getDataSource(ConnDefImpl.java:64)
at com.para.osc.framework.common.base.BaseDaoEntity.getConnection(BaseDaoEntity.java:25)
at com.paraview.jar.core.tools.ConnDefImpl.getConn(ConnDefImpl.java:96)
at com.paraview.jar.core.table.TableImpl.<init>(TableImpl.java:92)
at com.paraview.jar.core.table.TableImpl.getInstance(TableImpl.java:279)
at com.paraview.jar.core.factory.TableFactory.getTableHandler(TableFactory.java:40)
at com.paraview.jar.core.factory.TableFactory.getTableHandler(TableFactory.java:66)
at com.para.osc.framework.common.base.BaseDaoImpl.getTableInterface(BaseDaoImpl.java:21)
at com.para.osc.framework.common.base.DaoImpl.queryList(DaoImpl.java:424)
at com.para.osc.framework.security.service.impl.PrPasswordLogServiceImpl.query(PrPasswordLogServiceImpl.java:374)
at com.para.osc.framework.security.service.impl.PrPasswordLogServiceImpl$$FastClassByCGLIB$$b6a96355.invoke(<generated>)
at net.sf.cglib.proxy.MethodProxy.invoke(MethodProxy.java:149)
at org.springframework.aop.framework.Cglib2AopProxy$CglibMethodInvocation.invokeJoinpoint(Cglib2AopProxy.java:689)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:110)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:90)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
at org.springframework.aop.framework.Cglib2AopProxy$DynamicAdvisedInterceptor.intercept(Cglib2AopProxy.java:622)
at com.para.osc.framework.security.service.impl.PrPasswordLogServiceImpl$$EnhancerByCGLIB$$e2453cb0.query(<generated>)
at com.para.osc.framework.security.service.impl.PrEmployeeRequestLogServiceImpl.doProcessApplyPwdCheckOnline(PrEmployeeRequestLogServiceImpl.java:628)
at com.para.osc.framework.security.service.impl.PrEmployeeRequestLogServiceImpl$$FastClassByCGLIB$$fdf29789.invoke(<generated>)
at net.sf.cglib.proxy.MethodProxy.invoke(MethodProxy.java:149)
at org.springframework.aop.framework.Cglib2AopProxy$CglibMethodInvocation.invokeJoinpoint(Cglib2AopProxy.java:689)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:110)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:90)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
at org.springframework.aop.framework.Cglib2AopProxy$DynamicAdvisedInterceptor.intercept(Cglib2AopProxy.java:622)
at com.para.osc.framework.security.service.impl.PrEmployeeRequestLogServiceImpl$$EnhancerByCGLIB$$34c6beac.doProcessApplyPwdCheckOnline(<generated>)
at com.para.osc.framework.common.quartz.TimingFlowJobTasks$1.callback(TimingFlowJobTasks.java:48)
at com.para.osc.framework.common.quartz.ThreadSyncComponent.syncRun(ThreadSyncComponent.java:80)
at com.para.osc.framework.common.quartz.TimingFlowJobTasks.doApplyPwdCheckOnlineJob(TimingFlowJobTasks.java:44)
at sun.reflect.GeneratedMethodAccessor55.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:615)
at org.springframework.util.MethodInvoker.invoke(MethodInvoker.java:273)
at org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean$MethodInvokingJob.executeInternal(MethodInvokingJobDetailFactoryBean.java:311)
at org.springframework.scheduling.quartz.QuartzJobBean.execute(QuartzJobBean.java:113)
at org.quartz.core.JobRunShell.run(JobRunShell.java:223)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:665)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:690)
at java.lang.Thread.run(Thread.java:797)
Caused by: javax.naming.NameNotFoundException: Name not found in context "java:".
0 请登录后投票
   发表时间:2012-11-20  
晕啊,这点东西不足以做为呈堂证供,你跑好几天,没个日志怎么行,光看代码不是猜吗,如果内存溢出很难肉眼瞧出来的
0 请登录后投票
   发表时间:2012-12-05  
把需要每天调用的封装成一个类,然后每天调用下面这个定时器就好
import org.quartz.CronTrigger;
import org.quartz.JobDetail;
import org.quartz.Scheduler;
import org.quartz.SchedulerFactory;
import org.quartz.impl.StdSchedulerFactory;
import com.rensanning.M1Job;
public class UpsDetail{

public static void main(String[] args) {

try {
SchedulerFactory sf = new StdSchedulerFactory();
       
        Scheduler sched = sf.getScheduler();
               
        //每天7点钟扫描一次
        //String sconf1m = "10 */1 * * * ?";
        String sconf1m = "10 42 08 * * ?";
        //String sconf1m = "0 25 17 * * ?";
       

        M1Job m1job = new M1Job();
        JobDetail job1m = new JobDetail("job1m", "group1m", m1job.getClass());
        CronTrigger trigger1m = new CronTrigger("trigger1m", "group1m", "job1m", "group1m", sconf1m);
        sched.addJob(job1m, true);
        sched.scheduleJob(trigger1m);

        sched.start();
} catch (Exception e) {
e.printStackTrace();
}

}
}
0 请登录后投票
   发表时间:2012-12-05  
直接没有看下去的欲望了。你把格式弄好,很难吗。。。
0 请登录后投票
   发表时间:2013-01-07  
風一樣的男子 写道
apopo 写道
風一樣的男子 写道
sziitjiang 写道
hekuilove 写道
Rong_it 写道
風一樣的男子 写道
这格式不想看

me too 哈哈

me too.

me too. 用Eclipse的格式化代码控飘过,哈哈


团队协同开发禁止随意格式化代码
只允许选定自己修改的代码进行格式化

公司应该提供统一的格式化模板


不管是SVN、git、cvs还是啥
你已格式化,别人同步的时候就有可能冲突了

就算是SVN GIT CVS会冲突 可个人觉得不能放弃可读性吧?

作为一个团队可以执行统一的编码风格、规范嘛。
0 请登录后投票
   发表时间:2013-01-08  
有个疑问,人家run方法里面不是对所有可能发生的异常都捕获了吗?难道还有Exception之外的异常被抛出来;

另,我也遇到过别人写的Timer不知为何无法执行的情况。处理方法是设置适当的超时时间,在线程超出这个时间后,kill掉,重新启动一个线程执行任务。见博文:http://623deyingxiong.iteye.com/blog/1753975
0 请登录后投票
   发表时间:2013-01-09  
查看log,看看是不是多线程引起的死锁
0 请登录后投票
   发表时间:2013-02-16  
用quartz,基本没出过问题
0 请登录后投票
论坛首页 入门技术版

跳转论坛:
Global site tag (gtag.js) - Google Analytics