Java开发可能用到的代码片段
2012-09-04 00:00
393 查看
1.check if the input paramter is number:
if(!(args[1].trim().matches("[\\d.]+"))){
System.out.println("The input is not number.");
System.exit(-1);
}
2.将propertie文件读入内存
FileInputStream inputFile = new FileInputStream("filepath");
Properties propertie = new Properties();
propertie.load(inputFile);
inputFile.close();
3.java.util.Timer
与每个 Timer 对象相对应的是单个后台线程,用于顺序地执行所有计时器任务。计时器任务应该迅速完成。如果完成某个计时器任务的时间太长,那么它会“独占”计时器的任务执行线程。因此,这就可能延迟后续任务的执行,而这些任务就可能“堆在一起”,并且在上述不友好的任务最终完成时才能够被快速连续地执行
A facility for threads to schedule tasks for future execution in a background thread.
Tasks may be scheduled for one-time execution, or for repeated execution at regular intervals.
private void crontab(int delayTime,int spaceTime)
{
Timer timer = new Timer(true);
timer.schedule(new TimerTask(){
public void run(){
someTask();
}
},delayTime,spaceTime);
}
比较新的java API实现:
java.util.concurrent.ScheduledExecutorService.scheduleWithFixedDelay(Runnable command,long initialDelay,long delay,TimeUnit unit)
if(!(args[1].trim().matches("[\\d.]+"))){
System.out.println("The input is not number.");
System.exit(-1);
}
2.将propertie文件读入内存
FileInputStream inputFile = new FileInputStream("filepath");
Properties propertie = new Properties();
propertie.load(inputFile);
inputFile.close();
3.java.util.Timer
与每个 Timer 对象相对应的是单个后台线程,用于顺序地执行所有计时器任务。计时器任务应该迅速完成。如果完成某个计时器任务的时间太长,那么它会“独占”计时器的任务执行线程。因此,这就可能延迟后续任务的执行,而这些任务就可能“堆在一起”,并且在上述不友好的任务最终完成时才能够被快速连续地执行
A facility for threads to schedule tasks for future execution in a background thread.
Tasks may be scheduled for one-time execution, or for repeated execution at regular intervals.
private void crontab(int delayTime,int spaceTime)
{
Timer timer = new Timer(true);
timer.schedule(new TimerTask(){
public void run(){
someTask();
}
},delayTime,spaceTime);
}
比较新的java API实现:
java.util.concurrent.ScheduledExecutorService.scheduleWithFixedDelay(Runnable command,long initialDelay,long delay,TimeUnit unit)
相关文章推荐
- solr4.7.2开发实践 ——拼音检索【需要用到的包pinyin4j-2.5.0.jar和pinyinAnalyzer.jar;只需要配置schema.xml文件、solrj的java代码测试】
- Java开发常用的代码片段
- Java核心技术中的一个类GBC的代码(可能用到)
- 收藏的25个非常有用的CSS代码片段,在你开发基于CSS的网站时,这些代码是经常用到的,比方说一些特殊的效果,圆角边框,CSS透明度,梯形环绕,CSS小三角等,希望对你有用
- java web开发中要用到的各种文档
- 【常用JAVA代码片段】在android中如何打开文件节点,写节点
- 敏捷开发中编写高质量Java代码
- 敏捷开发中编写高质量Java代码
- 完整java开发中JDBC连接数据库代码和步骤
- 做Java用到的所有开发工具
- 完整java开发中JDBC链接数据库代码和步骤
- 完整java开发中JDBC连接数据库代码和步骤
- C#程序员经常用到的10个实用代码片段
- Java web开发中主要用到的jar包
- 十条jQuery代码片段助力Web开发效率提升
- 芒果iOS开发之代码片段Code Snippets Library
- 遍历查找集合或者数组中的某个元素的值 java代码 详解 Android开发
- android开发之java代码中如何获取到当前时间。详情代码带注释。
- Android开发之下载服务器上的一张图片到本地java代码实现HttpURLConnection
- 完整java开发中JDBC连接数据库代码和步骤