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();
Ïà¹ØÎĵµ£º
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
public class ZipUtil {
public static void main(String[] args) {
&nb ......
//1.JavaÖÐ×Ö·û´®²»ÄܶàÐÐÊéд¡£¶àÐÐÊéдÓÃÒýºÅ¸ô¶Ï£¬¼ÓºÅÏàÁ¬¡£
//2.JavaµÄ±êʶ·û¿ÉÒÔÓÃÃÀÔª·ûºÅ¿ªÍ·¡£
//3.JavaÖÐûÓÐÎÞ·ûºÅ±äÁ¿»òÎÞ·ûºÅ³£Á¿µÄ¸ÅÄî¡£ËùÓеıäÁ¿¶¼ÊÇÓзûºÅµÄ¡£
//4.JavaÖбäÁ¿µÄ×Ö³¤Êǹ̶¨µÄ¡£²»´æÔÚcharºÍwcharÖ®·Ö¡£
//5.JavaÖбäÁ¿Î ......
---------------------------------------
Asp.Net,C#,SQL,JS,WCF,AJAX,¹¤×÷Á÷,WPF,MVC,LINQ,Éè¼Æģʽ(¼Ü¹¹)µÈ¼¼ÊõÌÖÂÛ
“ASP.NET(C#)Fans” QQȺ£º96877690
---------------------------------------
²»¹ÜÊÇJ2SE¡¢J2EE»¹ÊÇJ2ME¾´Çë¼ÓÈ룡Eclipse¡¢NetBeans
Java½»Á÷QQ¸ß¼¶ÈºÀ©ÕУº96878255 ......
µÚÒ»£¬Ì¸Ì¸final, finally, finalizeµÄÇø±ð¡£
¡¡¡¡×î³£±»Îʵ½¡£¡¡¡¡
¡¡¡¡µÚ¶þ£¬Anonymous Inner Class (ÄäÃûÄÚ²¿Àà) ÊÇ·ñ¿ÉÒÔextends(¼Ì³Ð)ÆäËüÀ࣬ÊÇ·ñ¿ÉÒÔimplements(ʵÏÖ)interface(½Ó¿Ú)?¡¡¡¡
¡¡¡¡µÚÈý£¬Static Nested Class ºÍ Inner ClassµÄ²»Í¬£¬ËµµÃÔ½¶àÔ½ºÃ(ÃæÊÔÌâÓеĺÜÁýͳ)¡£¡¡¡¡
¡¡¡¡µÚËÄ£¬&ºÍ&am ......
±¾ÎÄÊ×ÏȽéÉÜjavaÁ¬½ÓoracleҪעÒâµÄ¼¸µã£¬È»ºó½éÉܼ¸ÖÖ³£ÓõÄÁ¬½Ó·½Ê½¡£
Ò»¡¢¼¸µã×¢Ò⣺
1¡¢ÔÚ¿Í»§¶ËÈí¼þ¿ª·¢ÖÐʹÓÃThinÇý¶¯³ÌÐò
ÔÚ¿ª·¢JavaÈí¼þ·½Ã棬OracleµÄÊý¾Ý¿âÌṩÁËËÄÖÖÀàÐ͵ÄÇý¶¯³ÌÐò£¬¶þÖÖÓÃÓÚÓ¦ÓÃÈí¼þ¡¢applets¡¢servletsµÈ¿Í»§¶ËÈí¼þ£¬ÁíÍâ¶þÖÖÓÃÓÚÊý¾Ý¿âÖеÄJava´æ´¢¹ý³ÌµÈ·þÎñÆ ......