明天的昨天的博客
明天的昨天 · 共 76 篇文章
CountDownLatch
http://www.javamex.com/tutorials/threads/CountDownLatch.shtml Coordinating threads with CountDownLatch The CountDownLatch class allows us to coordinate the starting and stopping of threads. Typical uses are as follows: we can make several threads start at the same time ; we can wait for several thr…
2011-01-24 23:26 · java并发编程实践 · 评论(0)
防御性拷贝(Defensive copying)
A mutable object is simply an object which can change its state after construction. For example, StringBuilder and Date are mutable objects, while String and Integer are immutable objects . A class may have a mutable object as a field. There are two possible cases for how the state of a mutable obj…
2011-01-18 22:27 · java并发编程实践 · 评论(0)
java之不可变对象2(immutable objects in java)
Immutable objects are simply objects whose state (the object's data) cannot change after construction. Examples of immutable objects from the JDK include String and Integer . Immutable objects greatly simplify your program, since they : are simple to construct, test, and use are automatically threa…
2011-01-18 22:15 · java并发编程实践 · 评论(0)
java之不可变对象1(immutable objects in java)
an immutable object is an object whose state cannot be modified after it is created. 不可变对象一旦被创建就它的状态就不能被修改。 A classic example of an immutable object is an instance of the Java String class. 不可变对象的一个经典的例子是String类的实例。 String s = "ABC"; s.toLowerCase(); The method toLowerCase() will not change the dat…
2011-01-18 21:53 · java并发编程实践 · 评论(0)
extjs combobox 只读
实现效果: extjs combobox 只读,也就是说只能从提供的列表中选择,而不能手动输入 只需要添加一个属性: editable: false
2011-01-18 11:26 · extjs · 评论(0)
java final 与 线程安全(Thread-safety)
Thread-safety with the Java final keyword 来源于:http://www.javamex.com/tutorials/synchronization_final.shtml As of Java 5, the final keyword is a very important and often overlooked(漏看,忽略 ) weapon in your concurrency armoury(军械库;武器厂 ). Essentially, final can be used to make sure that when you constru…
2011-01-18 01:00 · java并发编程实践 · 评论(0)
java final域
参考: http://liyuan2005.iteye.com/blog/209206 1. 当你在类中定义变量时,在其前面加上final关键字,那便是说,这个变量一旦被初始化便不可改变,这里不可改变的意思对基本类型来说是其值不可变,而对于对象变量来说其引用不可再变 。 2. 其初始化可以在两个地方,一是其定义处,也就是说在final变量定义时直接给其赋值,二是在构造函数中 。这两个 地方只能选其一,要么在定义时给值,要么在构造函数中给值,不能同时既在定义时给了值,又在构造函数中给另外的值。 3. 引用对象 can never be changed to point to another o…
2011-01-18 00:42 · Java核心 · 评论(0)
ubuntu9.10 快速搭建简易的ftp服务器
1. 安装vsftpd 打开终端,输入 sudo apt-get install vsftpd 2. 安装完毕后会自动生成一个帐户"ftp",/srv下也会增加一个ftp文件夹。 注意:1) 不同的ubuntu版本。这里生成的文件夹可能不一样。其他生成路径:/home/ftp 2) 不要修改/srv/ftp的权限为777.权限设置为755,匿名访问才可以。 3. 建立上传文件夹,这里设置为myftpfile 更改/srv/ftp/myftpfile目录权限。这一步很重要。否则不能创建文件和上传文件。 sudo chmod 777 /srv/ftp/myftpfile 4. 修改配置文件 通过…
2011-01-01 19:56 · linux · 评论(2)
java NIO 学习笔记2 Byte Buffers
学习资料来源:http://www.exampledepot.com/egs/java.nio/pkg.html 1. Converting Between a ByteBuffer an a Byte Array ByteBuffer与Byte数组的相互转化。 import java.nio.ByteBuffer; public class ConvertByteBufferByteArray { public static void main(String[] args) { //由Byte数组创建ByteBuffer byte[] bytes=new byte[10]; ByteBuf…
2010-12-16 11:00 · Java核心 · 评论(0)
java NIO 学习笔记1
jdon看到的一篇帖子。现记录如下。 问题: 很简单 100个请求过来了,每个请求都会有三个事件 ,accept,read write ,如果只有一个主线程轮询,每遍历到一个事件都得线性的去处理他,等处理完了再处理第二个事件,如果有个write的写操作要写很多数据,那也得等这个 write写完了再处理下一个, 要改善这种情况,还得用一个新线程去处理,或是线程池任务队列之类的处理也好,这样就不至于非得等到上一个事件处理完,那这样又回到了之前的阻塞 socket多线程处理用户请求的模式了, 非阻塞,非阻塞其实就是channel的write和read不会阻塞,读不到或是写不出去方法会马上返回,但是…
2010-12-15 15:52 · Java核心 · 评论(0)
IO流读文件 中文乱码
一段很简单读文件代码 public class TestFileReader { public static void main(String[] args) { FileReader fr=null; BufferedReader br=null; try { fr=new FileReader("D:/ncolog1.txt"); br=new BufferedReader(fr); String read=null; while((read=br.readLine())!=null){ System.out.println(read); } } catch (Exception e) …
2010-12-08 21:58 · Java核心 · 评论(0)
Common Errors in Setting Java Heap Size
Two JVM options are often used to tune JVM heap size: -Xmx for maximum heap size, and -Xms for initial heap size. Here are some common mistakes I have seen when using them: * Missing m, M, g or G at the end (they are case insensitive). For example, java -Xmx128 BigApp java.lang.OutOfMemoryError: Ja…
2010-11-03 14:40 · Java核心 · 评论(0)
Java:使用synchronized和Lock对象获取对象锁(转)
转自: http://zhangjunhd.blog.51cto.com/113473/70300 在并发环境下,解决共享资源冲突问题时,可以考虑使用锁机制。 1.对象的锁 所有对象都自动含有单一的锁。 JVM负责跟踪对象被加锁的次数。如果一个对象被解锁,其计数变为0。在任务(线程)第一次给对象加锁的时候,计数变为1。每当这个相同的任务(线程)在此对象上获得锁时,计数会递增。 只有首先获得锁的任务(线程)才能继续获取该对象上的多个锁。 每当任务离开一个synchronized方法,计数递减,当计数为0的时候,锁被完全释放,此时别的任务就可以使用此资源。 2.synchronized同步块 2…
2010-11-02 16:54 · java并发编程实践 · 评论(0)