2013年8月4日

摘要: package testAtomic;import java.util.concurrent.atomic.AtomicInteger;import sun.security.krb5.internal.Ticket;public class Tictit { private AtomicInteger ticitNumber;public Tictit (AtomicInteger ticAtomicInteger){ this.ticitNumber=ticAtomicInteger;}public AtomicInteger getTicitNumber() { return ticit 阅读全文
posted @ 2013-08-04 15:27 孟子hehe 阅读(308) 评论(0) 推荐(0) 编辑
 
摘要: AtomicInteger线程安全的根源,熟悉并发的同学一定知道在java中处理并发主要有两种方式:1,synchronized关键字,这个大家应当都各种面试和笔试中经常遇到。2,volatile修饰符的使用,相信这个修饰符大家平时在项目中使用的也不是很多。这里重点说一下volatile:Volatile修饰的成员变量在每次被线程访问时,都强迫从共享内存重新读取该成员的值,而且,当成员变量值发生变化时,强迫将变化的值重新写入共享内存,这样两个不同的线程在访问同一个共享变量的值时,始终看到的是同一个值。java语言规范指出:为了获取最佳的运行速度,允许线程保留共享变量的副本,当这个线程进入或者离 阅读全文
posted @ 2013-08-04 14:33 孟子hehe 阅读(616) 评论(0) 推荐(0) 编辑
 

2013年7月28日

摘要: public class MySynchronizedTest implements Runnable {//线程加锁时应是同一对象 int i=100; Object object=new Object(); boolean flag=true; //对方法加锁 public synchronized void count1() { while(flag){ try {//睡眠200ms Thread.sleep(200); } catch (InterruptedException e) { // TODO Auto-generated catch block ... 阅读全文
posted @ 2013-07-28 23:12 孟子hehe 阅读(169) 评论(0) 推荐(0) 编辑
 

2013年7月17日

摘要: import java.util.Properties;import javax.mail.Authenticator;import javax.mail.Message;import javax.mail.MessagingException;import javax.mail.PasswordAuthentication;import javax.mail.Session;import javax.mail.Transport;import javax.mail.internet.AddressException;import javax.mail.internet.InternetAdd 阅读全文
posted @ 2013-07-17 21:15 孟子hehe 阅读(204) 评论(0) 推荐(0) 编辑
 

2013年6月27日

摘要: http://docs.oracle.com/javase/1.5.0/docs/api/TheProcessBuilder.start()andRuntime.execmethods createa native processand return an instance of a subclass ofProcessthat can be used to control the process and obtain information about it. The classProcessprovides methods for performing input from the pro 阅读全文
posted @ 2013-06-27 23:18 孟子hehe 阅读(228) 评论(0) 推荐(0) 编辑
 
摘要: 声明:转载请注明出处static{}(即static块),会在类被加载的时候执行且仅会被执行一次,一般用来初始化静态变量和调用静态方法,下面我们详细的讨论一下该语句块的特性及应用。一、在程序的一次执行过程中,static{}语句块中的内容只被执行一次,看下面的示例:示例一view plaincopy to clipboardprint?class Test{ public static int X=100; public final static int Y;=200 public Test(){ System.out.println("Test构造函数执行"); } st 阅读全文
posted @ 2013-06-27 23:07 孟子hehe 阅读(207) 评论(0) 推荐(0) 编辑
 

2013年6月22日

摘要: package InterCeptor;import java.util.Iterator;import java.util.Map;import java.util.Map.Entry;import java.util.Set;import org.apache.commons.fileupload.disk.DiskFileItem;import org.apache.commons.fileupload.disk.DiskFileItemFactory;import org.apache.struts2.components.FieldError;import sun.reflect.F 阅读全文
posted @ 2013-06-22 00:17 孟子hehe 阅读(543) 评论(0) 推荐(0) 编辑
 

2013年6月14日

摘要: <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%><!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html><head><meta http-equiv=" 阅读全文
posted @ 2013-06-14 12:47 孟子hehe 阅读(232) 评论(0) 推荐(0) 编辑