`
文章列表

重入锁

重入锁(ReentrantLock)是一种递归无阻塞的同步机制。以前一直认为它是synchronized的简单替代,而且实现机制也不相差太远。不过最近实践过程中发现它们之间还是有着天壤之别。 以下是官方说明:一个可重入的互斥锁定 Lock,它具有与使用 synchronized 方法和语句所访问的隐式监视器锁定相同的一些基本行为和语义,但功能更强大。ReentrantLock 将由最近成功获得锁定,并且还没有释放该锁定的线程所拥有。当锁定没有被另一个线程所拥有时,调用 lock 的线程将成功获取该锁定并返回。如果当前线程已经拥有该锁定,此方法将立即返回。可以使用 isHeldByCurren ...

JSF之获取link的值

    博客分类:
  • JSF
<p:commandLink id="linkContractId" value="#{result.contractId}" onclick="dlg2.show();" style="color: blue;text-decoration :underline" actionListener="#{searchContractByLessorBean.linkClick}" update="contractDi ...
package com.thread; public class Joining { public static void main(String[] args) { Sleeper sleepy = new Sleeper("Sleepy",15000), grumpy = new Sleeper("Grumpy",15000); Joiner dopey = new Joiner("Dopey",sleepy), doc = new Joiner("Doc",gru ...
所谓的后台线程,是指在程序运行的时候在后台提供一种通用服务的线程,并且这种线程并不属于程序中不可或缺的部分。因此,当所有的非后台线程结束的时候,程序也就终止,同时会杀死所有的后台线程。 package com.thread; import java.util.concurrent.TimeUnit; public class SimpleDaemons implements Runnable{ public void run() { while(true) { try { TimeUnit.MILLISECONDS.sleep(100); S ...
2011/12/29 1:接到任务时候先进行分析,了解需求,直到需求明确,清晰才开始coding. 2:不盲目coding 3.Easy Explore. 2012/3/31 4.在遇到一件很难解决的问题的时候,需要学会放开眼光,用跳跃式的思想来思考,不能死脑筋,停留在一个原地琢磨,当你跳出去的时候,就会发现,其实问题很简单! 5.了解清楚业务不了解清楚技术更重要! 6.合理安排和任务的时间! 7.写代码的时候仔细点,可以避免以后花时间来检查。 8.遇到问题首先应该从基本点找起。 9.不要在一个问题上浪费超过一个小时,学会跳出怪圈,从外围去发现问题 10.每天花半小时总结,可以不断的发现问题和 ...
class TaskWithResult implements Callable<String>{ private int id; public int getId() { return id; } public TaskWithResult(int id) { super(); this.id = id; } public void setId(int id) { this.id = id; } /** * @param args */ public static void main(St ...
public class CachedthreadPool { public static void main(String[] args) { ExecutorService es = Executors.newCachedThreadPool(); for ( int i = 0; i< 5; i++) es.execute(new LiftOff()); es.shutdown(); } } public class MoreBasicThread { /** * @param args */ public s ...
1:定义任务: public class LiftOff implements Runnable{ private int count = 10; private static int taskCount = 0; private final int id = taskCount++; public void run() { while(count-- > 0) { System.out.println(status()); Thread.yield(); } } public String status() { return ...
package com.io; import java.io.BufferedOutputStream; import java.io.FileOutputStream; import java.io.IOException; import java.io.OutputStream; import java.util.Arrays; import java.util.List; import nu.xom.Document; import nu.xom.Element; import nu.xom.Serializer; public class XmlCtrTest ...
1。对象序列化: 序列化是什么:   序列化就是将一个对象的状态(各个属性量)保存起来,然后在适当的时候再获得。   序列化分为两大部分:序列化和反序列化。序列化是这个过程的第一部分,将数据分解成字节流,以便存储在文件中或在网络上传输。反序列化就是打开字节流并重构对象。对象序列化不仅要将基本数据类型转换成字节表示,有时还要恢复数据。恢复数据要求有恢复数据的对象实例   序列化的什么特点:   如果某个类能够被序列化,其子类也可以被序列化。声明为static和transient类型的成员数据不能被序列化。因为static代表类的状态, transient代表对象的临时数据。   什么时候使用序列化 ...
1.GZIP压缩: public class GZIPPcompress { public static void main(String[] args) throws IOException { if (args.length == 0) { System.out.println("Usage: \n GZIPcompress file\n" + " \tUses GZIP compresion to compress " + " the file to test.gz"); S ...
在读取大文件的时候,采用管道方式进行分流,使用byteBuffer把文件分成一段段的进行读写。 生成大文件 : public class ProductionFile { private static void productFile() throws FileNotFoundException { File file = new File("D://larger.txt"); PrintWriter pw = new PrintWriter(file); try{ for (int i = 0;i<1024;i++) { f ...
1.Charset 名称必须以字母或数字开头。空字符串不是合法的 charset 名称。Charset 名称是大小写不敏感的,也就是当比较 charset 名称时总是忽略大小写。Charset 名称通常遵循 RFC2278:IANA Charset Registration Procedures 中所记录的约定. 2.一些 charset 有一个历史名称,定义这个名称是为了和以前版本的 Java 平台兼容。charset 的历史名称既可以是它的规范名称,也可以是它的某个别名。历史名称由 InputStreamReader 和 OutputStreamWriter 类的 getEncoding() ...
1.获取文本的编码方式: String encoding = System.getProperty("file.encoding"); 2.获取缓存中的数据。 //encoding 为编码方式 Charset.forName(encoding).decode(buff)
缓冲器操纵数据: ByteBuffer是数据移进移出通道的唯一方式,使用ByteBuffer.wrap把子节数组包装起来然后用getChannel()方法在FileInputStream上打开一个通道,接着将来自于ByteBuffer的数据写入到FileChannel中。 ByteBuffer的方法详细: capacity()--->返回缓冲区容量 clear() --->清空缓冲区,将position设置为0,limit设置为容量。调用此方法可以覆写缓冲区。 flip() ---> 将limit设置为position,position设置为0,此方法用于准备从缓冲区读取已经 ...
Global site tag (gtag.js) - Google Analytics