赞
踩
public class ThreadTest1{private int j;public static void main(String args[]){ThreadTest1 tt=new ThreadTest1();Inc inc=tt.new Inc();Dec dec=tt.new Dec();for(int i=0;i<2;i++){Thread t=new Thread(inc);t.start();t=new Thread(dec);t.start();}}private synchronized void inc(){j++;System.out.println(Thread.currentThread().getName()+"-inc:"+j);}private synchronized void dec(){j--;System.out.println(Thread.currentThread().getName()+"-dec:"+j);}class Inc implements Runnable{public void run(){for(int i=0;i<100;i++){inc();}}}class Dec implements Runnable{public void run(){for(int i=0;i<100;i++){dec();}}}}
public class Singleton { private static Singleton instance = null; public static synchronized Singleton getInstance() { //这个方法比上面有所改进,不用每次都进行生成对象,只是第一次 //使用时生成实例,提高了效率! if (instance==null) instance=new Singleton();return instance; } }
Public String translate (String str) {String tempStr = "";try {tempStr = new String(str.getBytes("ISO-8859-1"), "GBK");tempStr = tempStr.trim();}catch (Exception e) {System.err.println(e.getMessage());}return tempStr;}
public void init(ServletConfig config)public ServletConfig getServletConfig()public String getServletInfo()public void service(ServletRequest request,ServletResponse response)public void destroy()
[code="java"]HelloHome home = (Home) PortableRemoteObject.narrow(ctx.lookup("Hello"), HelloHome.class);
[/code]
static i = 10; //常量class A a; a.i =10;//可变
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。