- 浏览: 84579 次
文章分类
最新评论
-
bailangfei3344:
自我介绍 -
regionwar:
你好,转化为人为:1、不该加锁的不要加锁:局部变量,单线程占用 ...
关于java锁机制的优化 -
danni505:
希望能交流:
msn:danni-505#hotmail.co ...
关于java锁机制的优化 -
ouspec:
收藏的东西不错。
TOP500 -
willpower:
The idea behind is e-sync IO do ...
Rethink the sync
Java shutdown hook guarantee that clean-up code is always run, regardless of how the user terminates the application.
Here is an example from Hadoop:
java 代码
- /**
- * A class to track the list of DFS clients, so that they can be closed
- * on exit.
- * @author Owen O'Malley
- */
- private static class ClientFinalizer extends Thread {
- private List clients = new ArrayList();
- public synchronized void addClient(DFSClient client) {
- clients.add(client);
- }
- public synchronized void run() {
- Iterator itr = clients.iterator();
- while (itr.hasNext()) {
- DFSClient client = (DFSClient) itr.next();
- if (client.running) {
- try {
- client.close();
- } catch (IOException ie) {
- System.err.println("Error closing client");
- ie.printStackTrace();
- }
- }
- }
- }
- }
- // add a cleanup thread
- private static ClientFinalizer clientFinalizer = new ClientFinalizer();
- static {
- Runtime.getRuntime().addShutdownHook(clientFinalizer);
- }
Elegant and useful!!!
发表评论
-
字符编码笔记:ASCII,Unicode和UTF-8 (引用)
2009-01-07 10:39 912字符编码笔记:ASCII,Unicode和UTF-8 阮一峰 ... -
How to set up a simple LRU cache using LinkedHash
2008-11-03 18:05 1274How to set up a simple LRU cach ... -
Scalability?
2008-10-07 14:07 819严格上讲,scalability还没有正式定义, 甚至有人觉得 ... -
Cray Reminiscences
2007-08-29 15:54 785Kirk Pepperdine's attendence of ... -
lock-free
2007-06-18 22:06 9851. http://www.ibm.com/developer ... -
解决java.lang.OutOfMemoryError: PermGen space(转帖)
2007-06-05 18:07 3156解决方案就是:在启动服务器时加上指定PermGen区域的内存大 ... -
Performance...
2007-06-05 15:11 973« I used to work for... | Mai ... -
数据仓库
2007-04-18 10:38 1112... -
Expressions Transform
2007-04-13 11:13 1383Expressions, Conversion and Eva ... -
Java performance tunning
2007-04-03 11:37 930http://www.javaperformancetunin ... -
Running IE from command line
2007-04-03 10:58 1102Here's a simple way you can ru ... -
Unicode and UTF8
2007-04-03 10:27 903What is Unicode? Unicode provid ... -
Daemon Thread Notes
2007-04-03 09:16 26441. 只要程式中的non-Daemon thread都結束了. ... -
How to know the main class of a jar file?
2007-04-02 15:18 1023Easy. Here is an implementation ... -
The best chinese BAT tutorial(from www.boofee.net/bigfee/)
2007-03-27 11:58 1325如何创建批处理文件? 不要听了批处理文件就感到很神气 ... -
Basics - Binary search
2007-03-26 15:53 962java 代码 public class Bin ... -
MergeSort
2007-03-23 17:26 823MergeSort is a sample solutio ... -
Graph data structure
2007-03-23 12:04 8721. adjacent matrix good for bor ... -
Functional Programming For The Rest of Us
2007-03-23 10:39 1263I like connect beautiful artic ... -
Functional Programming For The Rest of Us
2007-03-23 10:24 1058I like connect beautiful artic ...
相关推荐
But if code isn’t clean, it can bring a development organization to its knees. Every year, countless hours and significant resources are lost because of poorly written code. But it doesn’t have to ...
例如,通过导入预设的Eclipse格式模板文件(HuaXin_codetemplates.xml、HuaXin_Formatter.xml、HuaXin_CleanUp.xml),可自动实现代码注释、内容排版、清理无用变量等功能。 2.2 命名规范:涉及包、类与接口、方法...
Visual Studio Code works with all major Java versions from various vendors up to 13. To help you get started quickly, we created a special Installer of Visual Studio Code for Java developers. The ...
This book will teach the concepts of test driven development in Java so you can build clean, maintainable and robust code About This Book Explore the most popular TDD tools and frameworks and become...
Write code that's clean, concise, and to the point: code that others will read with pleasure and reuse. Comparing your code to that of expert programmers is a great way to improve your coding skills. ...
4. 对于`cleanup-profile.xml`,路径是`Java` -> `Code Style` -> `Clean Up`,同样点击右侧的`Import...`按钮导入。 5. 导入后,你可以根据需要预览和调整这些配置,然后应用到当前工作空间或特定项目。 通过这些...
例如,这里提到的`format_cleanup`可能就是这样的一个模板文件。 2. **导入模板**:在Eclipse中,选择`Window` -> `Preferences`进入设置界面。然后展开`Java` -> `Code Style` -> `Formatter`,点击右侧的`Import....
- **《Clean Code: A Handbook of Agile Software Craftsmanship》**:本书由Robert C. Martin(Uncle Bob)撰写,是关于编写清晰、简洁代码的经典之作。书中不仅介绍了多种设计模式的应用场景,还深入探讨了如何...
- 使用`Source > Clean Up`功能可以批量按照设定的规范格式化代码。 - 定义并启用代码检查器,如`Preferences > Java > Compiler > Errors/Warnings`,能帮助发现潜在的问题。 - 配置Eclipse的`Keys`,例如设置...
压缩包中包含了checkstyle-profile.xml,cleanup-profile.xml,codetemplates.xml,formatter-profile.xml四个代码格式化的配置文件,只需要在eclipse->window->preferences->java->code style中import对应的xml即可...
在“工具”这一标签中,我们看到的三个文件名——koudai-formatter.xml、koudai-cleanUp.xml、koudai-codetemplates.xml,它们分别对应了代码格式化、清理和代码模板的配置。这些工具通常与IDE(集成开发环境)如...
CleanUp.xml文件定义了这些规则,包括但不限于:导入排序、去除未使用的变量、统一缩进、转换为大驼峰命名等。使用此配置,可以快速地使代码符合编码标准。 4. **maven_settings.xml**: Maven是Java项目管理工具...
"Save Action"则是Eclipse的一项设置,允许在保存文件时自动执行特定操作,如格式化代码、删除未使用的导入(Cleanup)或添加缺少的导入(Auto Import)。 "Auto Import"是Eclipse的另一个重要特性,它能自动将所需...
清理:cleanup.xml 命名约定 Eclipse 项目名称约定 名称 评论 啊啊啊 pom 项目作为所有项目的父项目 aaa-common 通用代码:实用程序、常量、异常、... aaa-*-客户端 实体、服务接口 aaa-*-服务 EJB,服务实现 aaa-...
- 使用Eclipse的"Source"菜单中的"Clean Up"功能,自动按照当前代码风格对代码进行整理。 通过深入理解并充分利用Eclipse的内部配置和代码格式化设置,开发者可以更好地优化个人开发环境,提高代码质量,降低维护...
// clean up resources } ``` ### 断言(Assertions) 断言是一种调试工具,用于检查程序中假定为真的条件。自Java 1.4版本起,Java引入了断言机制,允许开发者在开发阶段进行测试和调试,确保程序状态符合预期,...