Java×Ô¶¨Òå¶àÏ̷߳þÎñÆ÷
// multi.MultiServer.java
package multi;
import java.io.IOException;
import java.net.InetSocketAddress;
import java.net.ServerSocket;
import java.net.Socket;
public class MultiServer {
private int port = 8000;
private int backlog = 42;
private ServerSocket server_socket;
private ThreadPool threadPool;
private final int POOL_SIZE = 7;
public MultiServer()throws IOException{
server_socket = new ServerSocket();
server_socket.setReuseAddress(true);
server_socket.bind(new InetSocketAddress(port),backlog);
int system_cpu_total = Runtime.getRuntime().availableProcessors();
threadPool = new ThreadPool(POOL_SIZE * system_cpu_total);
System.out.println("--- server started! ---");
}
public void service(){
while(true){
try{
Socket socket = server_socket.accept();
threadPool.execute(new WorkHandler(socket));
} catch(Exception e){
e.printStackTrace();
}
}
}
public static void main(String[] args)throws Exception {
MultiServer server = new MultiServer();
server.service();
}
}
// multi.ThreadPool.java
package multi;
import java.util.LinkedList;
public class ThreadPool extends ThreadGroup{
private static int threadPoolId;
private boolean isClosed = false;
private LinkedList<Runnable> workQueue;
public ThreadPool(int poolSize){
super("ThreadPool-" + (threadPoolId++));
setDaemon(true);
workQueue = new LinkedList<Runnable>();
for(int i=0;i<poolSize;i++){
new WorkThread(this,i).start(); // Æô¶¯¹¤×÷ÕßÏß³Ì
}
}
public synchronized void execute(Runnable task){
if(isClosed){
throw new IllegalStateException("The " + getName()
+ " has closed!");
}
if(task != null){
workQueue.add(task);
// Ò»´ÎÖ»ÓÐÒ»¸öÏß³ÌÈ¡ÈÎÎñ[getTask() ±» synchronized ÐÞÊÎ]
// ËùÓд˴¦Ã»ÓÐʹÓÃnotifyAll();
Ïà¹ØÎĵµ£º
·ºÐÍÊÇJ2SE 5.0×îÖØÒªµÄÌØÐÔ¡£ËûÃÇÈÃÄãдһ¸ötype(Àà»ò½Ó¿Ú£©ºÍ´´½¨Ò»¸öʵÀýͨ¹ý´«µÝÒ»¸ö»ò¶à¸öÒýÓÃÀàÐÍ¡£Õâ¸öʵÀýÊÜÏÞÓÚÖ»ÄÜ×÷ÓÃÓÚÕâЩÀàÐÍ¡£
±ÈÈ磬ÔÚjava 5£¬java.util.List ÒѾ±»·º»¯¡£µ±½¨Á¢Ò»¸ölist¶ÔÏóʱ£¬Äãͨ¹ý´«µÝÒ»¸öjavaÀàÐͽ¨Á¢Ò»¸öListʵÀý£¬´ËlistʵÀýÖ»ÄÜ×÷ÓÃÓÚËù´«µÝµÄÀàÐÍ¡£ÕâÒâζ×ÅÈç¹ûÄã´«µÝÒ»¸öSt ......
2010-03-10
×î½ü×öÏîÄ¿Óöµ½ÁËÒ»¸öÎÊÌ⣬ÐèÒª½«¿Í»§¶Ëµ½´¦µÄ¼ÓÃÜZIPѹËõ°üÖ±½Óµ¼È뵽ϵͳÖС£ÔÚÍøÉϲéÁËϹØÓÚZIP½âÃܵÄÎÊÌ⣬·¢ÏÖÁËwinzipaesÕâ¸ö¿ªÔ´ÏîÄ¿http://code.google.com/p/winzipaes £¬Õâ¸öÏîÄ¿ÐèÒªÒÀÀµbcprov-jdk14-145.jarÕâ¸ö¿ªÔ´°ü£¬Á½¸ö°üÁªºÏʹÓÿÉÒÔ½âÃÜAES -256Ëã·¨µÄ¼ÓÃÜÃÜÂë¡£
ÒòΪϵͳʹÓõÄÊÇJDK1.4 ......
1¡¢Ê×ÏȱØÐëÓиö½Ó¿Ú
package reflection;
public interface HelloWorld {
void sayHelloWorld();
void testHello(String hello);
}
2¡¢½Ó¿ÚµÄʵÏÖÀà
package reflection;
public class HelloWorldImpl implements HelloWorld {
public void sayHelloWorld() {
&n ......
JAVAÓïÑÔÖеķ´Éä»úÖÆ£º
ÔÚJava ÔËÐÐʱ »·¾³ÖУ¬¶ÔÓÚÈÎÒâÒ»¸öÀ࣬ÄÜ·ñÖªµÀÕâ¸öÀàÓÐÄÄЩÊôÐԺͷ½·¨£¿
¶ÔÓÚÈÎÒâÒ»¸ö¶ÔÏó£¬ÄÜ·ñµ÷ÓÃËûµÄ·½·¨£¿ÕâЩ´ð°¸Êǿ϶¨µÄ£¬ÕâÖÖ¶¯Ì¬»ñÈ¡ÀàµÄÐÅÏ¢£¬ÒÔ¼°¶¯Ì¬µ÷ÓÃÀàµÄ·½·¨µÄ¹¦ÄÜÀ´Ô´ÓÚJAVAµÄ·´Éä¡£´Ó¶øÊ¹java¾ßÓж¯Ì¬ÓïÑÔµÄÌØÐÔ¡£
JAVA·´É ......