How Java handles arguments of a class type.
=====suppose such a method:
public static void openFile(String fileName, PrintWriter stream) throws FileNotFoundException
{
stream = new PrintWriter(fileName);
}
=====then we want to use it this way:
PrintWriter toFile = null;
try
{
openFile("data.txt", toFile);
}
*****After this code is executed, the value of toFile is still null. The file that was opened in the method openFile went away when the method ended. The problem has to do with how Java handles arguments of a class type.
"These arguments are passed to the method as memory addresses that cannot be changed. The state of the object at the memory address normally can be changed, but the memory address itself cannot be changed"!
Ïà¹ØÎĵµ£º
http://www.onjava.com
O'ReillyµÄJavaÍøÕ¾. ÿÖܶ¼ÓÐÐÂÎÄÕÂ
http://java.sun.com
¹Ù·½µÄJava¿ª·¢ÕßÍøÕ¾ - ÿÖܶ¼ÓÐÐÂÎÄÕ·¢±í
http://www.developer.com/java
ÓÉGamelan.com ά»¤µÄJava¼¼ÊõÎÄÕÂÍøÕ¾
http://www.java.net
&nb ......
Ê×ÏÈ£¬java¶Ô¶ÔÏóºÍ»ù±¾ÀàÐ͵Ĵ¦ÀíÊDz»Ò»ÑùµÄ£¬ºÍCÓïÑÔÒ»Ñù£¬µ±°ÑJavaµÄ»ù±¾Êý¾ÝÀàÐÍ£¨Èçint£¬char£¬doubleµÈ£©×÷ΪÈë¿Ú²ÎÊý´«¸øº¯ÊýÌåµÄʱºò£¬´«ÈëµÄ²ÎÊýÔÚº¯ÊýÌåÄÚ²¿±ä³ÉÁ˾ֲ¿±äÁ¿£¬Õâ¸ö¾Ö²¿±äÁ¿ÊÇÊäÈë²ÎÊýµÄÒ»¸ö¿½±´£¬ËùÓеĺ¯ÊýÌåÄÚ²¿µÄ²Ù×÷¶¼ÊÇÕë¶ÔÕâ¸ö¿½±´µÄ²Ù×÷£¬º¯ÊýÖ´ÐнáÊøºó£¬Õâ¸ö¾Ö²¿±äÁ¿Ò²¾ÍÍê³ÉÁËËüµÄʹÃü£¬ ......
Abstract
ÔÚ¿ª·¢ÖУ¬Èç¹ûij¸öʵÀýµÄ´´½¨ÐèÒªÏûºÄºÜ¶àϵͳ×ÊÔ´£¬ÄÇôÎÒÃÇͨ³£»áʹÓöèÐÔ¼ÓÔØ»úÖÆ£¬Ò²¾ÍÊÇ˵ֻÓе±Ê¹Óõ½Õâ¸öʵÀýµÄʱºò²Å»á´´½¨Õâ¸öʵÀý£¬Õâ¸öºÃ´¦ÔÚ
µ¥ÀýģʽÖеõ½Á˹㷺ӦÓá£Õâ¸ö»úÖÆÔÚsingle-threaded»·¾³ÏµÄʵÏַdz£¼òµ¥£¬È»¶øÔÚmulti-threaded» ......
package test;
/**
*
* @author openpk
*/
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Semaphore;
public class Main {
public static void main(String[] args) {
// Ï̳߳Ø
ExecutorService exec = Executors ......