首页 > 编程语言 >Rules for good java.util.Timer use

Rules for good java.util.Timer use

时间:2023-09-14 12:04:38浏览次数:34  
标签:use good java thread color Timer will your


Many people have probably used Timer for some quick one-off timer tasks where using a whole library like Quartz don’t make sense.

One thing to be aware of is that Timer’s constructor will start and spawn a thread. This is a recipe for trouble if you use Timer too casually.

Two good rules of thumb for the use of Timer are:

1. [color=green]Always start your Timer as a daemon thread[/color]. By default, new Timer() and other constructors use a non-daemon thread which means that the Timer will stick around forever and prevent shutdown. That may be what you expect, but I doubt it.

2. [color=green]Always name your Timer[/color]. That name is attached to the Timer background thread. That way, if you do something dumb, and look at a thread dump, it will be exceedingly obvious when you’ve started 500 FooBarCleanupThreads.

标签:use,good,java,thread,color,Timer,will,your
From: https://blog.51cto.com/u_16261339/7468615

相关文章

  • java 日期函数
    得到过去的时间:exampleone:privateDategetDateTime(){ Calendarcalendar=Calendar.getInstance(); calendar.set(2011,Calendar.DECEMBER,1,23,0,0); returncalendar.getTime();}exampletwo:String.valueOf(newDate().getTime()-2......
  • (转)HashMap出现 java.util.ConcurrentModificationException
    Iterator<Integer>keys=gradeMap.keySet().iterator();while(keys.hasNext()){Integeri=keys.next();if(!gradesIds.contains(i)){//keys.remove();gradeMap.remove(i);}......
  • go 语言比java的优势提升编程效率的利器
    示例示例Go语言比Java有如下优势:Go语言的编译速度更快,可以提高开发效率。Go语言使用编译器进行编译,而Java使用解释器进行编译,Go的编译速度更快。Go语言比Java有如下优势:1.Go语言的编译速度更快,可以提高开发效率。Go语言使用编译器进行编译,而Java使用解释器进行编译......
  • Java8 Optional用法和最佳实践
    介绍根据Oracle文档,Optional是一个容器对象,可能包含也可能不包含非空值。Java8中引入它是为了解决NullPointerException的问题。本质上,Optional是一个包装类,其中包含对其他对象的引用。在这种情况下,对象只是指向内存位置的指针,它也可以指向任何内容。另一种看待它的方式......
  • JAVA-基本程序设计结构(类和对象)
    1.面向对象程序设计(OOP)1.概述1.类类(class)指定了如何构造对象。由一个类构造对象的过程称为创建这个类的一个实例。类是抽象的、概念的,代表一类事务,就是数据类型对象是具体的,实际的,代表一个具体事务,就是类的一个具体实例。类是对象的模板,对象是类的一个个体,对应一个实例......
  • 无涯教程-JavaScript - ISNONTEXT函数
    描述如果指定的值引用的不是文本,则ISNONTEXT函数将返回逻辑值TRUE。否则返回FALSE。如果该值引用空白单元格,则该函数返回TRUE。语法ISNONTEXT(value)争论Argument描述Required/OptionalvalueValueorexpressionorareferencetoacell.RequiredNotes您可以......
  • 关于 SAP CRM User Status 处理的示例 ABAP 代码
    源代码如下:*&---------------------------------------------------------------------**&ReportZSTATUS_INITIAL_LOAD*&---------------------------------------------------------------------**&*&----------------------------------------------......
  • tomcat报错:java.io.IOException: 您的主机中的软件中止了一个已建立的连接。页面响应
    tomcat报错:java.io.IOException:您的主机中的软件中止了一个已建立的连接。tomcat报错:org.apache.catalina.connector.ClientAbortException:java.io.IOException:您的主机中的软件中止了一个已建立的连接。 出现原因:1、由于客户端在发送请求后,还没等服务器响应就断开了......
  • 建民的JAVA课堂
    importjavax.swing.JOptionPane;publicclassMain{publicstaticvoidmain(String[]args){Stringfbb,rbb;//fbb=JoptionPane.ShowInputDialog("");JOptionPane.showConfirmDialog(null,"我的世界");JOpti......
  • Java有关队列的基本操作
    什么是队列?队列是一种线性数据结构,队列中的元素只能先进先出;队列的出口端叫做队头,入口端叫做队尾。队列的基本操作1.入队:只允许在队尾的位置放入元素,新元素的下一个位置将会成为新的队尾;publicvoidenQueue(intelement)throwsException{if((rea......