锘??xml version="1.0" encoding="utf-8" standalone="yes"?>亚洲国产精品自在自线观看,亚洲综合久久成人69,亚洲精品国产suv一区88http://www.tkk7.com/nikita/category/39100.htmlzh-cnThu, 09 Feb 2012 17:33:10 GMTThu, 09 Feb 2012 17:33:10 GMT60瑙e喅ServletUrlRenderer WARN璀﹀憡http://www.tkk7.com/nikita/archive/2012/02/09/369656.htmlpicture talkpicture talkThu, 09 Feb 2012 04:42:00 GMThttp://www.tkk7.com/nikita/archive/2012/02/09/369656.htmlhttp://www.tkk7.com/nikita/comments/369656.htmlhttp://www.tkk7.com/nikita/archive/2012/02/09/369656.html#Feedback1http://www.tkk7.com/nikita/comments/commentRss/369656.htmlhttp://www.tkk7.com/nikita/services/trackbacks/369656.html

]]>
Struts 2涓嶢JAX錛堢涓閮ㄥ垎錛?http://www.tkk7.com/nikita/archive/2011/08/07/355970.htmlpicture talkpicture talkSun, 07 Aug 2011 14:36:00 GMThttp://www.tkk7.com/nikita/archive/2011/08/07/355970.htmlhttp://www.tkk7.com/nikita/comments/355970.htmlhttp://www.tkk7.com/nikita/archive/2011/08/07/355970.html#Feedback0http://www.tkk7.com/nikita/comments/commentRss/355970.htmlhttp://www.tkk7.com/nikita/services/trackbacks/355970.htmlhttp://www.tkk7.com/max/archive/2007/06/12/123682.html

]]>
Fix Out of Memory errors by increasing available memory http://www.tkk7.com/nikita/archive/2010/09/09/331477.htmlpicture talkpicture talkThu, 09 Sep 2010 02:56:00 GMThttp://www.tkk7.com/nikita/archive/2010/09/09/331477.htmlhttp://www.tkk7.com/nikita/comments/331477.htmlhttp://www.tkk7.com/nikita/archive/2010/09/09/331477.html#Feedback0http://www.tkk7.com/nikita/comments/commentRss/331477.htmlhttp://www.tkk7.com/nikita/services/trackbacks/331477.html Go to start of metadata

I am getting Out of Memory errors, how can I allocate more memory to FishEye?

Since the default memory setting usually is around 64MB or 128MB, you might have to adjust the settings to run a bigger FishEye instance with sufficient memory.
On this page:


Out Of Memory Errors

There are a number of different memory errors that the JVM will throw. The most common are listed as follows.
In the following, you will be required to set your memory settings via your FISHEYE_OPTS Environment Variables.
You will need to restart your server after setting your FISHEYE_OPTS.

After having set the FISHEYE_OPTS and restarting your server, go to Administration > Sys Info/Support > System Info, and check your JVM Input Arguments to ensure that your server is picking up your FISHEYE_OPTS as expected.

OutOfMemoryError: Java Heap Space

If you are running Fisheye/Crucible as a windows service, increasing memory needs to be done in the wrapper.conf file. Refere to the Can Fisheye be run as a Windows Service for instructions.

To solve this error, you will need to add the argument -Xmx1024m to FISHEYE_OPTS, in addition to any argument you use to set the heap size. Often you need to increase the amount of memory allocated to fisheye during the initial scan and period and once this is completed you can reduce back down.

FISHEYE_OPTS="-Xms128m -Xmx1024m -XX:MaxPermSize=256m"

After having set the FISHEYE_OPTS and restarting your server, go to Administration > Sys Info/Support > System Info, and check your JVM Input Arguments to ensure that your server is picking up your FISHEYE_OPTS as expected.

OutOfMemoryError: PermGen space, or Permanent Generation Size

If you get the error message: java.lang.OutOfMemoryError: PermGen space this means that you have exceeded Java's fixed 64MB block for loading class files. You will need to add the argument -XX:MaxPermSize=256m to FISHEYE_OPTS, in addition to any argument you use to set the heap size.

FISHEYE_OPTS="-Xms128m -Xmx512m -XX:MaxPermSize=256m"

After having set the FISHEYE_OPTS and restarting your server, go to Administration > Sys Info/Support > System Info, and check your JVM Input Arguments to ensure that your server is picking up your FISHEYE_OPTS as expected.

OutOfMemoryError: unable to create new native thread

This error occurs when the operating system is unable to create new threads. This is due to the JVM Heap taking up the available RAM.

Big heaps take away from the space that can be allocated for the stack of a new thread

For Linux the maximum heap size of the JVM cannot be greater than 2GB. If you only have 2GB RAM in your server, it is not recommended to set the Max size of the JVM that high.
The size of the stack per thread can also contribute to this problem. The stack size can reduce the number of threads that can be created.

To fix this problem, you should reduce the size of your JVM Heap and also the size of the stack per thread.
The stack size can be changed with the following (example) parameter being added to your FISHEYE_OPTS:

FISHEYE_OPTS="-Xms128m -Xmx1024m -XX:MaxPermSize=256m -Xss512k"

Please refer to this guide as a reference for JVM tuning.

After having set the FISHEYE_OPTS and restarting your server, go to Administration > Sys Info/Support > System Info, and check your JVM Input Arguments to ensure that your server is picking up your FISHEYE_OPTS as expected.

OutOfMemoryError: GC overhead limit exceeded

This error indicates that the JVM took too long to free up memory during its GC process. This error can be thrown from the Parallel or Concurrent collectors.

The parallel collector will throw an OutOfMemoryError if too much time is being spent in garbage collection: if more than 98% of the total time is spent in garbage collection and less than 2% of the heap is recovered, an OutOfMemoryError will be thrown. This feature is designed to prevent applications from running for an extended period of time while making little or no progress because the heap is too small. If necessary, this feature can be disabled by adding the option -XX:-UseGCOverheadLimit to the command line.

This kind of OutOfMemoryError can be caused if your java process is starting to use swapped memory for its heap. This will cause the JVM to take a lot longer than normal to perform normal GC operations. This can eventually cause a timeout to occur and cause this error.

To overcome this issue, you need to make sure that all processes can't allocate more memory than there is system memory. In practice this is impossible to do for all processes. At a minimum you should make sure that all your jvm's do not have a total maximum memory allocation than your normally available system memory.

Please refer to this guide for more information.

java.lang.OutOfMemoryError: requested 32756 bytes for ChunkPool::allocate. Out of swap space?

Essentially the native objects does not have enough memory to use. This is usually because you have allocated too much memory to your heap reducing the amount available for native objects. See this article.

The solution is to reduce the amount of heap memory you have allocated. For example if you have set -Xmx4096, you should consider reducing this to -Xmx2048m.

Remember if you are using a 32bit JVM you cannot allocate more than -Xmx2048m for linux (and even less for windows). Using a 64 bit JVM can resolve this problem, but is not recommended for fisheye/crucible instances (refer to System Requirements).



Read the Tuning FishEye page for more detail on adjusting resource limits and performance settings in FishEye.


婧愯嚜 錛?a >http://confluence.atlassian.com/display/FISHEYE/Fix+Out+of+Memory+errors+by+increasing+available+memory#FixOutofMemoryerrorsbyincreasingavailablememory-OutOfMemoryError%3Aunabletocreatenewnativethread,



]]>
Problems Opening an Editor in Eclipsehttp://www.tkk7.com/nikita/archive/2010/06/21/324030.htmlpicture talkpicture talkMon, 21 Jun 2010 01:55:00 GMThttp://www.tkk7.com/nikita/archive/2010/06/21/324030.htmlhttp://www.tkk7.com/nikita/comments/324030.htmlhttp://www.tkk7.com/nikita/archive/2010/06/21/324030.html#Feedback0http://www.tkk7.com/nikita/comments/commentRss/324030.htmlhttp://www.tkk7.com/nikita/services/trackbacks/324030.html

I used to be able to open *.sql files in my Eclipse text editor. For some reason that stopped working this morning:

聽聽聽 Invalid menu handle.

InvalidMenuHandle

聽聽聽 Problems opening an editor... unable to open external editor.

ProblemsOpeningEditor

To fix this behavior for ALL files of a certain extension:

聽聽聽 Window > Preferences -

... and on the Preferences Tree:

聽聽聽 General > Editors > File Associations -

... add your File Type extension, for example *.sql

... and finally add your Associated Editor. I chose "internal editors" - "text editor"

TextEditorPreferences

You can also change the behavior "temporarily" for a single file. Right click the file, click "Open With..." and select the editor...

OpenWith



]]>
The Java serialization algorithm revealedhttp://www.tkk7.com/nikita/archive/2010/04/10/317951.htmlpicture talkpicture talkSat, 10 Apr 2010 09:20:00 GMThttp://www.tkk7.com/nikita/archive/2010/04/10/317951.htmlhttp://www.tkk7.com/nikita/comments/317951.htmlhttp://www.tkk7.com/nikita/archive/2010/04/10/317951.html#Feedback0http://www.tkk7.com/nikita/comments/commentRss/317951.htmlhttp://www.tkk7.com/nikita/services/trackbacks/317951.html Serialization is the process of saving an object's state to a sequence of bytes; deserialization is the process of rebuilding those bytes into a live object. The Java Serialization API provides a standard mechanism for developers to handle object serialization. In this tip, you will see how to serialize an object, and why serialization is sometimes necessary. You'll learn about the serialization algorithm used in Java, and see an example that illustrates the serialized format of an object. By the time you're done, you should have a solid knowledge of how the serialization algorithm works and what entities are serialized as part of the object at a low level.

Why is serialization required?

In today's world, a typical enterprise application will have multiple components and will be distributed across various systems and networks. In Java, everything is represented as objects; if two Java components want to communicate with each other, there needs be a mechanism to exchange data. One way to achieve this is to define your own protocol and transfer an object. This means that the receiving end must know the protocol used by the sender to re-create the object, which would make it very difficult to talk to third-party components. Hence, there needs to be a generic and efficient protocol to transfer the object between components. Serialization is defined for this purpose, and Java components use this protocol to transfer objects.

Figure 1 shows a high-level view of client/server communication, where an object is transferred from the client to the server through serialization.

A high-level view of serialization in action

Figure 1. A high-level view of serialization in action (click to enlarge)

How to serialize an object

In order to serialize an object, you need to ensure that the class of the object implements the java.io.Serializable interface, as shown in Listing 1.

Listing 1. Implementing Serializable

				
import java.io.Serializable;

class TestSerial implements Serializable {
public byte version = 100;
public byte count = 0;
}

In Listing 1, the only thing you had to do differently from creating a normal class is implement the java.io.Serializable interface. The Serializable interface is a marker interface; it declares no methods at all. It tells the serialization mechanism that the class can be serialized.

Now that you have made the class eligible for serialization, the next step is to actually serialize the object. That is done by calling the writeObject() method of the java.io.ObjectOutputStream class, as shown in Listing 2.

Listing 2. Calling writeObject()

				
public static void main(String args[]) throws IOException {
FileOutputStream fos = new FileOutputStream("temp.out");
ObjectOutputStream oos = new ObjectOutputStream(fos);
TestSerial ts = new TestSerial();
oos.writeObject(ts);
oos.flush();
oos.close();
}

Listing 2 stores the state of the TestSerial object in a file called temp.out. oos.writeObject(ts); actually kicks off the serialization algorithm, which in turn writes the object to temp.out.

To re-create the object from the persistent file, you would employ the code in Listing 3.

Listing 3. Recreating a serialized object

				
public static void main(String args[]) throws IOException {
FileInputStream fis = new FileInputStream("temp.out");
ObjectInputStream oin = new ObjectInputStream(fis);
TestSerial ts = (TestSerial) oin.readObject();
System.out.println("version="+ts.version);
}

In Listing 3, the object's restoration occurs with the oin.readObject() method call. This method call reads in the raw bytes that we previously persisted and creates a live object that is an exact replica of the original object graph. Because readObject() can read any serializable object, a cast to the correct type is required.

Executing this code will print version=100 on the standard output.

The serialized format of an object

What does the serialized version of the object look like? Remember, the sample code in the previous section saved the serialized version of the TestSerial object into the file temp.out. Listing 4 shows the contents of temp.out, displayed in hexadecimal. (You need a hexadecimal editor to see the output in hexadecimal format.)

Listing 4. Hexadecimal form of TestSerial

				
AC ED 00 05 73 72 00 0A 53 65 72 69 61 6C 54 65
73 74 A0 0C 34 00 FE B1 DD F9 02 00 02 42 00 05
63 6F 75 6E 74 42 00 07 76 65 72 73 69 6F 6E 78
70 00 64

If you look again at the actual TestSerial object, you'll see that it has only two byte members, as shown in Listing 5.

Listing 5. TestSerial's byte members

				
public byte version = 100;
public byte count = 0;

The size of a byte variable is one byte, and hence the total size of the object (without the header) is two bytes. But if you look at the size of the serialized object in Listing 4, you'll see 51 bytes. Surprise! Where did the extra bytes come from, and what is their significance? They are introduced by the serialization algorithm, and are required in order to to re-create the object. In the next section, you'll explore this algorithm in detail.

Java's serialization algorithm

By now, you should have a pretty good knowledge of how to serialize an object. But how does the process work under the hood? In general the serialization algorithm does the following:

  • It writes out the metadata of the class associated with an instance.
  • It recursively writes out the description of the superclass until it finds java.lang.object.
  • Once it finishes writing the metadata information, it then starts with the actual data associated with the instance. But this time, it starts from the topmost superclass.
  • It recursively writes the data associated with the instance, starting from the least superclass to the most-derived class.

I've written a different example object for this section that will cover all possible cases. The new sample object to be serialized is shown in Listing 6.

Listing 6. Sample serialized object

				
class parent implements Serializable {
int parentVersion = 10;
}

class contain implements Serializable{
int containVersion = 11;
}
public class SerialTest extends parent implements Serializable {
int version = 66;
contain con = new contain();

public int getVersion() {
return version;
}
public static void main(String args[]) throws IOException {
FileOutputStream fos = new FileOutputStream("temp.out");
ObjectOutputStream oos = new ObjectOutputStream(fos);
SerialTest st = new SerialTest();
oos.writeObject(st);
oos.flush();
oos.close();
}
}

This example is a straightforward one. It serializes an object of type SerialTest, which is derived from parent and has a container object, contain. The serialized format of this object is shown in Listing 7.

Listing 7. Serialized form of sample object

				
AC ED 00 05 73 72 00 0A 53 65 72 69 61 6C 54 65
73 74 05 52 81 5A AC 66 02 F6 02 00 02 49 00 07
76 65 72 73 69 6F 6E 4C 00 03 63 6F 6E 74 00 09
4C 63 6F 6E 74 61 69 6E 3B 78 72 00 06 70 61 72
65 6E 74 0E DB D2 BD 85 EE 63 7A 02 00 01 49 00
0D 70 61 72 65 6E 74 56 65 72 73 69 6F 6E 78 70
00 00 00 0A 00 00 00 42 73 72 00 07 63 6F 6E 74
61 69 6E FC BB E6 0E FB CB 60 C7 02 00 01 49 00
0E 63 6F 6E 74 61 69 6E 56 65 72 73 69 6F 6E 78
70 00 00 00 0B

Figure 2 offers a high-level look at the serialization algorithm for this scenario.

An outline of the serialization algorithm

Figure 2. An outline of the serialization algorithm

Let's go through the serialized format of the object in detail and see what each byte represents. Begin with the serialization protocol information:

  • AC ED: STREAM_MAGIC. Specifies that this is a serialization protocol.
  • 00 05: STREAM_VERSION. The serialization version.
  • 0x73: TC_OBJECT. Specifies that this is a new Object.

The first step of the serialization algorithm is to write the description of the class associated with an instance. The example serializes an object of type SerialTest, so the algorithm starts by writing the description of the SerialTest class.

  • 0x72: TC_CLASSDESC. Specifies that this is a new class.
  • 00 0A: Length of the class name.
  • 53 65 72 69 61 6c 54 65 73 74: SerialTest, the name of the class.
  • 05 52 81 5A AC 66 02 F6: SerialVersionUID, the serial version identifier of this class.
  • 0x02: Various flags. This particular flag says that the object supports serialization.
  • 00 02: Number of fields in this class.

Next, the algorithm writes the field int version = 66;.

  • 0x49: Field type code. 49 represents "I", which stands for Int.
  • 00 07: Length of the field name.
  • 76 65 72 73 69 6F 6E: version, the name of the field.

And then the algorithm writes the next field, contain con = new contain();. This is an object, so it will write the canonical JVM signature of this field.

  • 0x74: TC_STRING. Represents a new string.
  • 00 09: Length of the string.
  • 4C 63 6F 6E 74 61 69 6E 3B: Lcontain;, the canonical JVM signature.
  • 0x78: TC_ENDBLOCKDATA, the end of the optional block data for an object.

The next step of the algorithm is to write the description of the parent class, which is the immediate superclass of SerialTest.

  • 0x72: TC_CLASSDESC. Specifies that this is a new class.
  • 00 06: Length of the class name.
  • 70 61 72 65 6E 74: SerialTest, the name of the class
  • 0E DB D2 BD 85 EE 63 7A: SerialVersionUID, the serial version identifier of this class.
  • 0x02: Various flags. This flag notes that the object supports serialization.
  • 00 01: Number of fields in this class.

Now the algorithm will write the field description for the parent class. parent has one field, int parentVersion = 100;.

  • 0x49: Field type code. 49 represents "I", which stands for Int.
  • 00 0D: Length of the field name.
  • 70 61 72 65 6E 74 56 65 72 73 69 6F 6E: parentVersion, the name of the field.
  • 0x78: TC_ENDBLOCKDATA, the end of block data for this object.
  • 0x70: TC_NULL, which represents the fact that there are no more superclasses because we have reached the top of the class hierarchy.

So far, the serialization algorithm has written the description of the class associated with the instance and all its superclasses. Next, it will write the actual data associated with the instance. It writes the parent class members first:

  • 00 00 00 0A: 10, the value of parentVersion.

Then it moves on to SerialTest.

  • 00 00 00 42: 66, the value of version.

The next few bytes are interesting. The algorithm needs to write the information about the contain object, shown in Listing 8.

Listing 8. The contain object

				
contain con = new contain();

Remember, the serialization algorithm hasn't written the class description for the contain class yet. This is the opportunity to write this description.

  • 0x73: TC_OBJECT, designating a new object.
  • 0x72: TC_CLASSDESC.
  • 00 07: Length of the class name.
  • 63 6F 6E 74 61 69 6E: contain, the name of the class.
  • FC BB E6 0E FB CB 60 C7: SerialVersionUID, the serial version identifier of this class.
  • 0x02: Various flags. This flag indicates that this class supports serialization.
  • 00 01: Number of fields in this class.

Next, the algorithm must write the description for contain's only field, int containVersion = 11;.

  • 0x49: Field type code. 49 represents "I", which stands for Int.
  • 00 0E: Length of the field name.
  • 63 6F 6E 74 61 69 6E 56 65 72 73 69 6F 6E: containVersion, the name of the field.
  • 0x78: TC_ENDBLOCKDATA.

Next, the serialization algorithm checks to see if contain has any parent classes. If it did, the algorithm would start writing that class; but in this case there is no superclass for contain, so the algorithm writes TC_NULL.

  • 0x70: TC_NULL.

Finally, the algorithm writes the actual data associated with contain.

  • 00 00 00 0B: 11, the value of containVersion.

Conclusion

In this tip, you have seen how to serialize an object, and learned how the serialization algorithm works in detail. I hope this article gives you more detail on what happens when you actually serialize an object.

From 聽錛?http://www.javaworld.com/community/node/2915



]]>
宓屽綾誨拰鍐呴儴綾?/title><link>http://www.tkk7.com/nikita/archive/2009/10/14/298294.html</link><dc:creator>picture talk</dc:creator><author>picture talk</author><pubDate>Wed, 14 Oct 2009 15:26:00 GMT</pubDate><guid>http://www.tkk7.com/nikita/archive/2009/10/14/298294.html</guid><wfw:comment>http://www.tkk7.com/nikita/comments/298294.html</wfw:comment><comments>http://www.tkk7.com/nikita/archive/2009/10/14/298294.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.tkk7.com/nikita/comments/commentRss/298294.html</wfw:commentRss><trackback:ping>http://www.tkk7.com/nikita/services/trackbacks/298294.html</trackback:ping><description><![CDATA[ <font size="2">聽鏉ヨ嚜: <a href="/lincode/archive/2008/08/13/221594.html">http://www.tkk7.com/lincode/archive/2008/08/13/221594.html</a><br /><br />涓 姒傚康錛?br /><br />Java灝嗗祵濂楃被鍒嗘垚涓や釜涓昏鐨勫垎綾伙細闈欐佸祵濂楃被錛坰tatic nested classes錛夊拰鍐呴儴綾伙紙inner classes錛夈?br /><br />1 <strong>宓屽綾?/strong>錛坣ested classes錛夛紝鍦ㄤ竴涓被鍐呴儴瀹氫箟鐨勫彟涓涓被錛岀О涓哄祵濂楃被銆?br />聽 宓屽綾誨垎涓轟袱縐嶏紝 static 淇グ鐨?闈欐佸祵濂楃被錛?鍜屾棤 static 淇グ鐨?闈為潤鎬佸祵濂楃被錛屼篃鍙綔 鍐呴儴綾匯?br /><br />2 <strong>鍐呴儴綾?/strong>錛坕nner classes錛夛紝 鏃?static 淇グ鐨?闈為潤鎬佸祵濂楃被銆?br /><br />Java榪樿繘涓姝ュ皢鍐呴儴綾誨垎涓猴細<br /><br /><strong>瀹炰緥鍐呴儴綾?/strong>錛坕nstance inner class錛?錛屽亣璁懼湪澹版槑宓屽綾繪椂錛屾病鏈夊湪鍓嶉潰鍔犱笂static鍏抽敭瀛椼傝繖鏍峰緱鍒扮殑鏄釜瀹炰緥鍐呴儴綾匯傞潤鎬佸祵濂楃被鍙兘澶熻闂閮ㄧ被鐨剆tatic鎴愬憳錛岃屽疄渚嬪唴閮ㄧ被鑳藉鍚屾椂璁塊棶static鍜屽疄渚嬫垚鍛樸?br /><br /><strong>鏈湴鍐呴儴綾?/strong>錛坙ocal inner class錛夛紝Java鍏佽鍦ㄤ換鎰忕殑浠g爜孌典腑鏀懼叆涓涓被錛岃綾葷殑浠g爜鏀懼湪涓瀵瑰ぇ鎷彿涓瓄聽 }銆傝繖鎰忓懗鐫綾昏兘澶熷嚭鐜板湪涓涓柟娉曚腑錛岀敋鑷蟲槸鍦╥f璇彞鐨勪竴瀵規嫭鍙蜂腑銆傝繖鏍風殑綾誨氨縐頒負鏈湴鍐呴儴綾匯傜浉瀵逛簬瀹炰緥鍐呴儴綾繪潵璇達紝鏈湴鍐呴儴綾誨拰鏈変竴涓ソ澶勩備粬闄や簡鑳藉璁塊棶澶栭儴綾葷殑瀹炰緥鍜岀被瀛楁澶栵紙縐頒負瀹炰緥鍜岀被鏂規硶錛夛紝榪樿兘澶熻闂湰鍦板彉閲忓拰鏂規硶鐨勫弬鏁般?br /><br /><strong>鍖垮悕鍐呴儴綾?/strong>錛坅nd anonymous inner class錛夛紝娌℃湁緇欏嚭綾誨悕鐨勫唴閮ㄧ被涓哄尶鍚嶅唴閮ㄧ被銆?br /><br />浜?浣跨敤錛?br /><br />1. 璁塊棶鍐呴儴綾伙細<br /><br />鎴戜滑鍙互鍦ㄥ祵濂楃被錛堝寘鎷潤鎬佺殑鍜岄潪闈欐佺殑 錛夊墠鍔犱笂 private錛宲rotected 鎴?public 鍏抽敭瀛楋紝浠ユ寚紺鴻綾誨湪澶栭儴綾諱互澶栫殑璁塊棶綰у埆銆?br /><br />鍏蜂綋璁塊棶鏂規硶濡備笅錛?br />(1).鍐呴儴綾伙紝瑕佷互濡備笅褰㈠紡璁塊棶錛?outclass 鏄?OutClass 鐨勪竴涓疄渚嬶紝瀹冩斁鍦?new 鍓嶆寚紺哄唴閮ㄧ被鐨勫疄渚嬫槸灞炰簬涓涓壒瀹氱殑澶栭儴綾葷殑瀹炰緥鐨勩?榪欐槸鍥犱負錛屽彧鏈夊閮ㄧ被鐨勫疄渚嬪瓨鍦紝浠栫殑瀹炰緥鍐呴儴綾伙紙 涔熷氨鏄潪闈欐佸唴閮ㄧ被錛夋墠鑳藉瓨鍦ㄣ?br /></font> <span style="COLOR: rgb(0,128,0)"> <br /> <font size="2">聽聽 //</font> </span> <font size="2"> <span style="COLOR: rgb(0,128,0)"> innerclass</span> <br /> <span style="COLOR: rgb(0,0,0)">聽 OutClass聽outclass聽</span> <span style="COLOR: rgb(0,0,0)">=</span> <span style="COLOR: rgb(0,0,0)">聽</span> <span style="COLOR: rgb(0,0,255)">new</span> </font> <span style="COLOR: rgb(0,0,0)"> <font size="2">聽OutClass();<br />聽 </font> </span> <span style="COLOR: rgb(0,128,0)"> <br /> </span> <font size="2"> <span style="COLOR: rgb(0,0,0)">聽聽OutClass.InnerClass聽innerclass聽</span> <span style="COLOR: rgb(0,0,0)">=</span> <span style="COLOR: rgb(0,0,0)">聽outclass.</span> <span style="COLOR: rgb(0,0,255)">new</span> </font> <font size="2"> <span style="COLOR: rgb(0,0,0)">聽InnerClass();<br />聽聽innerclass.normalMethod();</span> <br /> <br />(2).闈欐佸祵濂楃被錛?鍙互鐢?OutClass.StaticInnerClass 鏉ユ寚紺恒?br />闈欐佸祵濂楃被錛屽彲浠ユ湁瀹炰緥鎴愬憳錛堝疄渚嬫柟娉?鍜?瀹炰緥鍙橀噺錛?br />璁塊棶闈欐佸祵濂楃被鐨勫疄渚嬪煙錛岄渶瑕佸厛瀹炰緥鍖栭潤鎬佸祵濂楃被銆?br />榪欎釜綾繪槸闈欐佺殑錛屽畠涓嶄緷璧栦簬瀹冨閮ㄧ被鐨勬煇涓疄渚嬶紝鎵浠ユ棤欏誨厛瀹炰緥鍖栧閮ㄧ被銆傝繖鍜屽唴閮ㄧ被鏄笉涓鏍風殑銆?br /><br /><span style="COLOR: rgb(0,0,0)">聽 OutClass.StaticInnerClass聽staticinnerclass聽</span><span style="COLOR: rgb(0,0,0)">=</span><span style="COLOR: rgb(0,0,0)">聽</span><span style="COLOR: rgb(0,0,255)">new</span></font> <font size="2"> <span style="COLOR: rgb(0,0,0)">聽OutClass.StaticInnerClass();<br />聽聽staticinnerclass.normalMethod();</span> <br /> <br />(3).闈欐佸祵濂楃被鐨勯潤鎬佹柟娉曪紝鍙互鐢?OutClass.StaticInnerClass.<span style="COLOR: rgb(0,0,0)">staticMethod() 鏉ヨ闂?/span><br /><br />瀹炰緥浠g爜錛?br /></font> <div style="BORDER-RIGHT: rgb(204,204,204) 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: rgb(204,204,204) 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: rgb(204,204,204) 1px solid; WIDTH: 98%; PADDING-TOP: 4px; BORDER-BOTTOM: rgb(204,204,204) 1px solid; BACKGROUND-COLOR: rgb(238,238,238)"> <font size="2"> <span style="COLOR: rgb(0,128,0)">//</span> <span style="COLOR: rgb(0,128,0)">聽OutClass.java</span> </font> <span style="COLOR: rgb(0,128,0)"> <br /> </span> <font size="2"> <span style="COLOR: rgb(0,0,255)">public</span> <span style="COLOR: rgb(0,0,0)">聽</span> <span style="COLOR: rgb(0,0,255)">class</span> </font> <font size="2"> <span style="COLOR: rgb(0,0,0)">聽OutClass聽{<br /><br />聽聽聽聽</span> <span style="COLOR: rgb(0,128,0)">//</span> <span style="COLOR: rgb(0,128,0)"> non static inner classes</span> </font> <span style="COLOR: rgb(0,128,0)"> <br /> </span> <font size="2"> <span style="COLOR: rgb(0,0,0)">聽聽聽聽</span> <span style="COLOR: rgb(0,0,255)">class</span> </font> <font size="2"> <span style="COLOR: rgb(0,0,0)">聽InnerClass{<br />聽聽聽聽<br />聽聽聽聽聽聽聽聽</span> <span style="COLOR: rgb(0,0,255)">public</span> <span style="COLOR: rgb(0,0,0)">聽</span> <span style="COLOR: rgb(0,0,255)">void</span> </font> <font size="2"> <span style="COLOR: rgb(0,0,0)">聽normalMethod(){<br />聽聽聽聽聽聽聽聽聽聽聽聽System.out.println(</span> <span style="COLOR: rgb(0,0,0)">"</span> <span style="COLOR: rgb(0,0,0)">聽success: non-static innerclass</span> <span style="COLOR: rgb(0,0,0)">"</span> </font> <font size="2"> <span style="COLOR: rgb(0,0,0)">);<br />聽聽聽聽聽聽聽聽}<br />聽聽聽聽}<br />聽聽聽聽<br />聽聽聽聽</span> <span style="COLOR: rgb(0,128,0)">//</span> <span style="COLOR: rgb(0,128,0)"> static inner classes</span> </font> <span style="COLOR: rgb(0,128,0)"> <br /> </span> <font size="2"> <span style="COLOR: rgb(0,0,0)">聽聽聽聽</span> <span style="COLOR: rgb(0,0,255)">static</span> <span style="COLOR: rgb(0,0,0)">聽</span> <span style="COLOR: rgb(0,0,255)">class</span> </font> <font size="2"> <span style="COLOR: rgb(0,0,0)">聽StaticInnerClass<br />聽聽聽聽{<br />聽聽聽聽聽聽聽聽</span> <span style="COLOR: rgb(0,128,0)">//</span> <span style="COLOR: rgb(0,128,0)">non聽static聽method of static inner classes</span> </font> <span style="COLOR: rgb(0,128,0)"> <br /> </span> <font size="2"> <span style="COLOR: rgb(0,0,0)">聽聽聽聽聽聽聽聽</span> <span style="COLOR: rgb(0,0,255)">public</span> <span style="COLOR: rgb(0,0,0)">聽</span> <span style="COLOR: rgb(0,0,255)">void</span> </font> <font size="2"> <span style="COLOR: rgb(0,0,0)">聽normalMethod()<br />聽聽聽聽聽聽聽聽{<br />聽聽聽聽聽聽聽聽聽聽聽聽System.out.println(</span> <span style="COLOR: rgb(0,0,0)">"</span> <span style="COLOR: rgb(0,0,0)">聽success:聽non聽static聽method of聽static聽innerclas</span> <span style="COLOR: rgb(0,0,0)">"</span> </font> <font size="2"> <span style="COLOR: rgb(0,0,0)">);<br />聽聽聽聽聽聽聽聽}<br />聽聽聽聽聽聽聽聽<br />聽聽聽聽聽聽聽聽</span> <span style="COLOR: rgb(0,128,0)">//</span> <span style="COLOR: rgb(0,128,0)">聽static聽methode聽of static inner classes</span> </font> <span style="COLOR: rgb(0,128,0)"> <br /> </span> <font size="2"> <span style="COLOR: rgb(0,0,0)">聽聽聽聽聽聽聽聽</span> <span style="COLOR: rgb(0,0,255)">static</span> <span style="COLOR: rgb(0,0,0)">聽</span> <span style="COLOR: rgb(0,0,255)">public</span> <span style="COLOR: rgb(0,0,0)">聽</span> <span style="COLOR: rgb(0,0,255)">void</span> </font> <font size="2"> <span style="COLOR: rgb(0,0,0)">聽staticMethod()<br />聽聽聽聽聽聽聽聽{<br />聽聽聽聽聽聽聽聽聽聽聽聽System.out.println(</span> <span style="COLOR: rgb(0,0,0)">"</span> <span style="COLOR: rgb(0,0,0)">聽success:聽static聽method of聽static聽innerclass</span> <span style="COLOR: rgb(0,0,0)">"</span> </font> <font size="2"> <span style="COLOR: rgb(0,0,0)">);<br />聽聽聽聽聽聽聽聽}<br />聽聽聽聽}<br />} </span> <span style="COLOR: rgb(0,128,0)">//</span> <span style="COLOR: rgb(0,128,0)"> end of InnerClass</span> <br /> </font> <span style="COLOR: rgb(0,0,0)"> <br /> </span> <font size="2"> <span style="COLOR: rgb(0,128,0)">//</span> <span style="COLOR: rgb(0,128,0)">聽Test.java</span> </font> <span style="COLOR: rgb(0,128,0)"> <br /> </span> <font size="2"> <span style="COLOR: rgb(0,0,255)">public</span> <span style="COLOR: rgb(0,0,0)">聽</span> <span style="COLOR: rgb(0,0,255)">class</span> </font> <font size="2"> <span style="COLOR: rgb(0,0,0)">聽Test聽{<br /><br /></span> <span style="COLOR: rgb(0,0,255)">public</span> <span style="COLOR: rgb(0,0,0)">聽</span> <span style="COLOR: rgb(0,0,255)">static</span> <span style="COLOR: rgb(0,0,0)">聽</span> <span style="COLOR: rgb(0,0,255)">void</span> </font> <font size="2"> <span style="COLOR: rgb(0,0,0)">聽main(String[]聽args){<br /><br />聽聽OutClass聽outclass聽</span> <span style="COLOR: rgb(0,0,0)">=</span> <span style="COLOR: rgb(0,0,0)">聽</span> <span style="COLOR: rgb(0,0,255)">new</span> </font> <font size="2"> <span style="COLOR: rgb(0,0,0)">聽OutClass();<br />聽聽<br />聽聽</span> <span style="COLOR: rgb(0,128,0)">//</span> <span style="COLOR: rgb(0,128,0)">聽innerclass</span> </font> <span style="COLOR: rgb(0,128,0)"> <br /> </span> <font size="2"> <span style="COLOR: rgb(0,0,0)">聽聽OutClass.InnerClass聽innerclass聽</span> <span style="COLOR: rgb(0,0,0)">=</span> <span style="COLOR: rgb(0,0,0)">聽outclass.</span> <span style="COLOR: rgb(0,0,255)">new</span> </font> <font size="2"> <span style="COLOR: rgb(0,0,0)">聽InnerClass();<br />聽聽innerclass.normalMethod();<br />聽聽<br />聽聽</span> <span style="COLOR: rgb(0,128,0)">//</span> <span style="COLOR: rgb(0,128,0)">聽non聽static聽method of聽static聽innerclas</span> </font> <span style="COLOR: rgb(0,128,0)"> <br /> </span> <font size="2"> <span style="COLOR: rgb(0,0,0)">聽聽OutClass.StaticInnerClass聽staticinnerclass聽</span> <span style="COLOR: rgb(0,0,0)">=</span> <span style="COLOR: rgb(0,0,0)">聽</span> <span style="COLOR: rgb(0,0,255)">new</span> </font> <font size="2"> <span style="COLOR: rgb(0,0,0)">聽OutClass.StaticInnerClass();<br />聽聽staticinnerclass.normalMethod();<br /><br />聽聽</span> <span style="COLOR: rgb(0,128,0)">//</span> <span style="COLOR: rgb(0,128,0)">聽static聽method of聽static聽innerclass</span> </font> <span style="COLOR: rgb(0,128,0)"> <br /> </span> <font size="2"> <span style="COLOR: rgb(0,0,0)">聽聽OutClass.StaticInnerClass.staticMethod();聽 <br />聽聽}<br />}</span> <span style="COLOR: rgb(0,128,0)">//</span> </font> <span style="COLOR: rgb(0,128,0)"> <font size="2"> end of Test<br /></font> </span> </div> <br /> <font size="2">2. 宓屽綾?璁塊棶 澶栭儴綾葷殑鎴愬憳錛?br /><br />(1). 澶栭儴綾誨浜庡唴閮ㄧ被錛堥潪闈欐佸祵濂楃被錛夋槸閫忔槑鐨勩傚寘鎷閮ㄧ被鐨刾rivate鎴愬憳錛屽叾鍐呴儴綾婚兘鍙互鑷敱璁塊棶銆?br /><br />(2). 涓涓潤鎬佸祵濂楃被鍙兘璁塊棶澶栭儴綾葷殑闈欐佹柟娉曪紝瀹冩槸涓嶈兘璁塊棶浠諱綍澶栭儴綾葷殑瀹炰緥鎴愬憳錛堝寘鎷彉閲忓拰鏂規硶錛夈?br /><br />(3). 鍐呴儴綾諱腑鐨?this 鏄寚鍐呴儴綾繪湰韜傚唴閮ㄧ被鐨勬垚鍛樺拰澶栭儴綾葷殑鎴愬憳鍚嶅啿紿侊紝鍐呴儴綾誨唴錛屽啿紿佺殑鎴愬憳鍚嶆槸鎸囧唴閮ㄧ被鎴愬憳銆?br />瑕佽皟鐢ㄥ閮ㄧ被鐨勫啿紿佺殑鎴愬憳錛岃浠?澶栭儴綾葷殑綾誨悕 鎸囩ず錛氬浜庡啿紿佺殑鍙橀噺 OutClass.conflitName聽 瀵逛簬鍐茬獊鐨勬柟娉?OutClass.conflitName()銆?br /></font> <img src ="http://www.tkk7.com/nikita/aggbug/298294.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.tkk7.com/nikita/" target="_blank">picture talk</a> 2009-10-14 23:26 <a href="http://www.tkk7.com/nikita/archive/2009/10/14/298294.html#Feedback" target="_blank" style="text-decoration:none;">鍙戣〃璇勮</a></div>]]></description></item><item><title>Bitwise logical operators in javahttp://www.tkk7.com/nikita/archive/2009/10/08/297414.htmlpicture talkpicture talkWed, 07 Oct 2009 17:06:00 GMThttp://www.tkk7.com/nikita/archive/2009/10/08/297414.htmlhttp://www.tkk7.com/nikita/comments/297414.htmlhttp://www.tkk7.com/nikita/archive/2009/10/08/297414.html#Feedback0http://www.tkk7.com/nikita/comments/commentRss/297414.htmlhttp://www.tkk7.com/nikita/services/trackbacks/297414.html1- The AND operator : (&)

Code:

x聽 聽 聽 聽 聽 聽y聽 聽 聽 聽 聽 聽 聽 聽 聽x&y聽
-----------------------------
0聽 聽 聽 聽 聽 聽0聽 聽 聽 聽 聽 聽 聽 聽 聽 0
0聽 聽 聽 聽 聽 聽1聽 聽 聽 聽 聽 聽 聽 聽 聽 0
1聽 聽 聽 聽 聽 聽0聽 聽 聽 聽 聽 聽 聽 聽 聽 0
1聽 聽 聽 聽 聽 聽1聽 聽 聽 聽 聽 聽 聽 聽 聽 1


Example on & operator

Code:

聽 聽 聽byte x = 50;
聽 聽 聽byte y = 51;
聽 聽 聽byte result = (byte) (x&y);
聽 聽 System.out.println("Result of x&y= : " + result );



The result equal = 50

00110010
00110011
-------------
00110010

2- The OR operator : (|)

Code:

x聽 聽 聽 聽 聽 聽y聽 聽 聽 聽 聽 聽 聽 聽 聽x|y聽
-----------------------------
0聽 聽 聽 聽 聽 聽0聽 聽 聽 聽 聽 聽 聽 聽 聽 0
0聽 聽 聽 聽 聽 聽1聽 聽 聽 聽 聽 聽 聽 聽 聽 1
1聽 聽 聽 聽 聽 聽0聽 聽 聽 聽 聽 聽 聽 聽 聽 1
1聽 聽 聽 聽 聽 聽1聽 聽 聽 聽 聽 聽 聽 聽 聽 1


Example on | operator

Code:

聽 聽 聽byte x = 50;
聽 聽 聽byte y = 51;
聽 聽 聽byte result = (byte) (x|y);
聽 聽 System.out.println("Result of x|y= : " + result );



The result equal = 51

00110010
00110011
-------------
00110011

3- The XOR operator : (^)

Code:

x聽 聽 聽 聽 聽 聽y聽 聽 聽 聽 聽 聽 聽 聽 聽x^y聽
-----------------------------
0聽 聽 聽 聽 聽 聽0聽 聽 聽 聽 聽 聽 聽 聽 聽 0
0聽 聽 聽 聽 聽 聽1聽 聽 聽 聽 聽 聽 聽 聽 聽 1
1聽 聽 聽 聽 聽 聽0聽 聽 聽 聽 聽 聽 聽 聽 聽 1
1聽 聽 聽 聽 聽 聽1聽 聽 聽 聽 聽 聽 聽 聽 聽 0


Example on ^ operator

Code:

聽 聽 聽byte x = 50;
聽 聽 聽byte y = 51;
聽 聽 聽byte result = (byte) (x^y);
聽 聽 System.out.println("Result of x^y= : " + result );



The result equal = 1

00110010
00110011
-------------
00000001


4- The Inversion Operator: (~)
Invert each bit in the byte .

Example :
Code:
~00110010 = 11001101



5- Boolean Inversion Operator (!)
invert the value of boolean


]]>
weak reference http://www.tkk7.com/nikita/archive/2009/05/17/271082.htmlpicture talkpicture talkSat, 16 May 2009 16:12:00 GMThttp://www.tkk7.com/nikita/archive/2009/05/17/271082.htmlhttp://www.tkk7.com/nikita/comments/271082.htmlhttp://www.tkk7.com/nikita/archive/2009/05/17/271082.html#Feedback0http://www.tkk7.com/nikita/comments/commentRss/271082.htmlhttp://www.tkk7.com/nikita/services/trackbacks/271082.htmlHashMap to look up a cache of objects. A weak reference is a reference that does not keep the object it refers to alive. A weak reference is not counted as a reference in garbage collection. If the object is not referred to elsewhere as well, it will be garbage collected.

The GC will send some sort of "finalize" message to the object and then set any weakly-referencing variables to null whenever it disposes of the referenced object. This allows "finalization" logic to be run before the object is disposed of (e.g., close a file if still open, commit any open transaction(s), etc.). Java 1.1 does not support weak references other than via an undocumented Ref class that is not supported under Netscape. Weak references arrived officially with JDK 1.2. Java has three kinds of weak references, called soft references, weak references, and phantom references, in order of increasing weakness.

Java has four orders of strength in holding onto Objects. In descending order from strongest to weakest they are:

  1. The JVM holds onto regular Objects until they are no longer reachable by either clients or any container. In other words Objects are garbage collected when there are no more live references to them. Dead references don鈥檛 count.
  2. Soft references can be deleted from a container if the clients are no longer referencing them and memory is tight.
  3. Weak references are automatically deleted from a container as soon clients stop referencing them.
  4. Phantom references point to objects that are already dead and have been finalised.


]]>
ClassLoader鍘熺悊http://www.tkk7.com/nikita/archive/2009/05/16/271078.htmlpicture talkpicture talkSat, 16 May 2009 15:38:00 GMThttp://www.tkk7.com/nikita/archive/2009/05/16/271078.htmlhttp://www.tkk7.com/nikita/comments/271078.htmlhttp://www.tkk7.com/nikita/archive/2009/05/16/271078.html#Feedback0http://www.tkk7.com/nikita/comments/commentRss/271078.htmlhttp://www.tkk7.com/nikita/services/trackbacks/271078.html聽JVM瑙勮寖瀹氫箟浜嗕袱縐嶇被鍨嬬殑綾昏杞藉櫒錛?strong>鍚姩鍐呰杞藉櫒(bootstrap)鍜岀敤鎴瘋嚜瀹氫箟瑁呰澆鍣?/strong>(user-defined class loader)銆?

涓錛幝犅犅?ClassLoader鍩烘湰姒傚康
1錛嶤lassLoader鍒嗙被
綾昏杞藉櫒鏄敤鏉ユ妸綾?class)瑁呰澆榪汮VM鐨勩?br />JVM瑙勮寖瀹氫箟浜嗕袱縐嶇被鍨嬬殑綾昏杞藉櫒錛?strong>鍚姩鍐呰杞藉櫒
(bootstrap)鍜岀敤鎴瘋嚜瀹氫箟瑁呰澆鍣?/strong>(user-defined class loader)銆?


JVM鍦ㄨ繍琛屾椂浼氫駭鐢熶笁涓狢lassLoader:Bootstrap聽ClassLoader銆丒xtension聽ClassLoader鍜孉ppClassLoader.Bootstrap鏄敤C++緙栧啓鐨勶紝鎴戜滑鍦↗ava涓湅涓嶅埌瀹?鏄痭ull,鏄疛VM鑷甫鐨勭被瑁呰澆鍣紝鐢ㄦ潵瑁呰澆鏍稿績綾誨簱錛屽java.lang.*絳夈?br />AppClassLoader鐨?/strong>Parent鏄?/strong>ExtClassLoader錛岃?/strong>ExtClassLoader鐨?/strong>Parent涓?/strong>Bootstrap聽ClassLoader銆?/strong>

Java鎻愪緵浜嗘娊璞$被ClassLoader錛屾墍鏈夌敤鎴瘋嚜瀹氫箟綾昏杞藉櫒閮藉疄渚嬪寲鑷?/strong>ClassLoader鐨勫瓙綾匯?/strong> System Class Loader鏄竴涓壒孌婄殑鐢ㄦ埛鑷畾涔夌被瑁呰澆鍣紝鐢?/strong>JVM鐨勫疄鐜拌呮彁渚涳紝鍦ㄧ紪紼嬭呬笉鐗瑰埆鎸囧畾瑁呰澆鍣ㄧ殑鎯呭喌涓嬮粯璁よ杞界敤鎴風被銆傜郴緇熺被瑁呰澆鍣ㄥ彲浠ラ氳繃ClassLoader.getSystemClassLoader() 鏂規硶寰楀埌銆?br />聽
渚?錛屾祴璇曚綘鎵浣跨敤鐨凧VM鐨凜lassLoader
/*LoaderSample1.java*/
publicclass聽LoaderSample1聽{
聽聽聽聽
publicstaticvoid聽main(String[]聽args)聽{
聽聽聽聽聽聽聽聽Class聽c;
聽聽聽聽聽聽聽聽ClassLoader聽cl;
聽聽聽聽聽聽聽聽cl聽
=聽ClassLoader.getSystemClassLoader();
聽聽聽聽聽聽聽聽System.out.println(cl);
聽聽聽聽聽聽聽聽
while聽(cl聽!=null)聽{
聽聽聽聽聽聽聽聽聽聽聽聽cl聽
=聽cl.getParent();
聽聽聽聽聽聽聽聽聽聽聽聽System.out.println(cl);
聽聽聽聽聽聽聽聽}
聽聽聽聽聽聽聽聽
try聽{
聽聽聽聽聽聽聽聽聽聽聽聽c聽
=聽Class.forName("java.lang.Object");
聽聽聽聽聽聽聽聽聽聽聽聽cl聽
=聽c.getClassLoader();
聽聽聽聽聽聽聽聽聽聽聽聽System.out.println(
"java.lang.Object's聽loader聽is聽"+聽cl);
聽聽聽聽聽聽聽聽聽聽聽聽c聽
=聽Class.forName("LoaderSample1");
聽聽聽聽聽聽聽聽聽聽聽聽cl聽
=聽c.getClassLoader();
聽聽聽聽聽聽聽聽聽聽聽聽System.out.println(
"LoaderSample1's聽loader聽is聽"+聽cl);
聽聽聽聽聽聽聽聽}聽
catch聽(Exception聽e)聽{
聽聽聽聽聽聽聽聽聽聽聽聽e.printStackTrace();
聽聽聽聽聽聽聽聽}
聽聽聽聽}
}


鍦ㄦ垜鐨勬満鍣ㄤ笂(Sun Java 1.4.2)鐨勮繍琛岀粨鏋?br />sun.misc.Launcher$AppClassLoader@1a0c10f
sun.misc.Launcher$ExtClassLoader@e2eec8
null
java.lang.Object's loader is null
LoaderSample1's loader is sun.misc.Launcher$AppClassLoader@1a0c10f

絎竴琛岃〃紺猴紝緋葷粺綾昏杞藉櫒瀹炰緥鍖栬嚜綾籹un.misc.Launcher$AppClassLoader
絎簩琛岃〃紺猴紝緋葷粺綾昏杞藉櫒鐨刾arent瀹炰緥鍖栬嚜綾籹un.misc.Launcher$ExtClassLoader
絎笁琛岃〃紺猴紝緋葷粺綾昏杞藉櫒parent鐨刾arent涓篵ootstrap
絎洓琛岃〃紺猴紝鏍稿績綾籮ava.lang.Object鏄敱bootstrap瑁呰澆鐨?
絎簲琛岃〃紺猴紝鐢ㄦ埛綾籐oaderSample1鏄敱緋葷粺綾昏杞藉櫒瑁呰澆鐨?


浜岋紟parent delegation妯″瀷
浠?.2鐗堟湰寮濮嬶紝Java寮曞叆浜嗗弻浜插鎵樻ā鍨嬶紝浠庤屾洿濂界殑淇濊瘉Java騫沖彴鐨勫畨鍏ㄣ?strong>鍦ㄦ妯″瀷涓嬶紝褰撲竴涓杞藉櫒琚姹傝杞芥煇涓被鏃訛紝瀹冮鍏堝鎵樿嚜宸辯殑
parent鍘昏杞斤紝鑻?/strong>parent鑳借杞斤紝鍒欒繑鍥炶繖涓被鎵瀵瑰簲鐨?/strong>Class瀵硅薄錛岃嫢parent涓嶈兘瑁呰澆錛屽垯鐢?/strong>parent鐨勮姹傝呭幓瑁呰澆銆?br />
鍥?1 parent delegation妯″瀷
濡傚浘1鎵紺猴紝loader2鐨刾arent涓簂oader1錛宭oader1鐨刾arent涓簊ystem class loader銆傚亣璁緇oader2琚姹傝杞界被MyClass錛屽湪parent delegation妯″瀷涓嬶紝loader2棣栧厛璇鋒眰loader1浠d負瑁呰澆錛宭oader1鍐嶈姹傜郴緇熺被瑁呰澆鍣ㄥ幓瑁呰澆MyClass銆傝嫢緋葷粺瑁呰澆鍣ㄨ兘鎴愬姛瑁呰澆錛屽垯灝哅yClass鎵瀵瑰簲鐨凜lass瀵硅薄鐨剅eference榪斿洖緇檒oader1錛宭oader1鍐嶅皢reference榪斿洖緇檒oader2錛屼粠鑰屾垚鍔熷皢綾籑yClass瑁呰澆榪涜櫄鎷熸満銆傝嫢緋葷粺綾昏杞藉櫒涓嶈兘瑁呰澆MyClass錛宭oader1浼氬皾璇曡杞組yClass錛岃嫢loader1涔熶笉鑳芥垚鍔熻杞斤紝loader2浼氬皾璇曡杞姐傝嫢鎵鏈夌殑parent鍙妉oader2鏈韓閮戒笉鑳借杞斤紝鍒欒杞藉け璐ャ?br />聽
鑻ユ湁涓涓兘鎴愬姛瑁呰澆錛屽疄闄呰杞界殑綾昏杞藉櫒琚О涓哄畾涔夌被瑁呰澆鍣紝鎵鏈夎兘鎴愬姛榪斿洖Class瀵硅薄鐨勮杞藉櫒錛堝寘鎷畾涔夌被瑁呰澆鍣級琚О涓哄垵濮嬬被瑁呰澆鍣ㄣ傚鍥?鎵紺猴紝鍋囪loader1瀹為檯瑁呰澆浜哅yClass錛屽垯loader1涓篗yClass鐨勫畾涔夌被瑁呰澆鍣紝loader2鍜宭oader1涓篗yClass鐨勫垵濮嬬被瑁呰澆鍣ㄣ?br />聽
闇瑕佹寚鍑虹殑鏄紝Class Loader鏄璞★紝瀹冪殑鐖跺瓙鍏崇郴鍜岀被鐨勭埗瀛愬叧緋繪病鏈変換浣曞叧緋匯?br />聽
閭d箞parent delegation妯″瀷涓轟粈涔堟洿瀹夊叏浜嗭紵鍥犱負鍦ㄦ妯″瀷涓嬬敤鎴瘋嚜瀹氫箟鐨勭被瑁呰澆鍣ㄤ笉鍙兘瑁呰澆搴旇鐢辯埗浜茶杞藉櫒瑁呰澆鐨勫彲闈犵被錛屼粠鑰岄槻姝笉鍙潬鐢氳嚦鎭舵剰鐨勪唬鐮佷唬鏇跨敱鐖朵翰瑁呰澆鍣ㄨ杞界殑鍙潬浠g爜銆傚疄闄呬笂錛岀被瑁呰澆鍣ㄧ殑緙栧啓鑰呭彲浠ヨ嚜鐢遍夋嫨涓嶇敤鎶婅姹傚鎵樼粰parent錛屼絾姝e涓婃墍璇達紝浼氬甫鏉ュ畨鍏ㄧ殑闂銆?/strong>


涓夛紟鍛藉悕絀洪棿鍙婂叾浣滅敤
姣忎釜綾昏杞藉櫒鏈夎嚜宸辯殑鍛藉悕絀洪棿錛屽懡鍚嶇┖闂寸敱鎵鏈変互姝よ杞藉櫒涓哄垱濮嬬被瑁呰澆鍣ㄧ殑綾葷粍鎴愩備笉鍚屽懡鍚嶇┖闂寸殑涓や釜綾繪槸涓嶅彲瑙佺殑錛屼絾鍙寰楀埌綾繪墍瀵瑰簲鐨凜lass瀵硅薄鐨剅eference錛岃繕鏄彲浠ヨ闂彟涓鍛藉悕絀洪棿鐨勭被銆?br />聽
渚?婕旂ず浜嗕竴涓懡鍚嶇┖闂寸殑綾誨浣曚嬌鐢ㄥ彟涓鍛藉悕絀洪棿鐨勭被銆傚湪渚嬪瓙涓紝LoaderSample2鐢辯郴緇熺被瑁呰澆鍣ㄨ杞斤紝LoaderSample3鐢辮嚜瀹氫箟鐨勮杞藉櫒loader璐熻矗瑁呰澆錛屼袱涓被涓嶅湪鍚屼竴鍛藉悕絀洪棿錛屼絾LoaderSample2寰楀埌浜哃oaderSample3鎵瀵瑰簲鐨凜lass瀵硅薄鐨剅eference錛屾墍浠ュ畠鍙互璁塊棶LoaderSampl3涓叕鍏辯殑鎴愬憳(濡俛ge)銆?br />渚?涓嶅悓鍛藉悕絀洪棿鐨勭被鐨勮闂?br />/*LoaderSample2.java*/

import聽java.net.*;
import聽java.lang.reflect.*;
publicclass聽LoaderSample2聽{
聽聽聽聽
publicstaticvoid聽main(String[]聽args)聽{
聽聽聽聽聽聽聽聽
try聽{
聽聽聽聽聽聽聽聽聽聽聽聽String聽path聽
=聽System.getProperty("user.dir");
聽聽聽聽聽聽聽聽聽聽聽聽URL[]聽us聽
=聽{new聽URL("file://"+聽path聽+"/sub/")};
聽聽聽聽聽聽聽聽聽聽聽聽ClassLoader聽loader聽
=new聽URLClassLoader(us);
聽聽聽聽聽聽聽聽聽聽聽聽Class聽c聽
=聽loader.loadClass("LoaderSample3");
聽聽聽聽聽聽聽聽聽聽聽聽Object聽o聽
=聽c.newInstance();
聽聽聽聽聽聽聽聽聽聽聽聽Field聽f聽
=聽c.getField("age");
聽聽聽聽聽聽聽聽聽聽聽聽
int聽age聽=聽f.getInt(o);
聽聽聽聽聽聽聽聽聽聽聽聽System.out.println(
"age聽is聽"+聽age);
聽聽聽聽聽聽聽聽}聽
catch聽(Exception聽e)聽{
聽聽聽聽聽聽聽聽聽聽聽聽e.printStackTrace();
聽聽聽聽聽聽聽聽}
聽聽聽聽}
}


/*sub/Loadersample3.java*/

publicclass聽LoaderSample3聽{
聽聽聽聽
static聽{
聽聽聽聽聽聽聽聽System.out.println(
"LoaderSample3聽loaded");
聽聽聽聽}
聽聽聽聽
publicint聽age聽=30;
}

緙栬瘧錛歫avac LoaderSample2.java; javac sub/LoaderSample3.java
榪愯錛歫ava LoaderSample2
LoaderSample3 loaded
age is 30
浠庤繍琛岀粨鏋滀腑鍙互鐪嬪嚭錛屽湪綾籐oaderSample2涓彲浠ュ垱寤哄浜庡彟涓鍛藉悕絀洪棿鐨勭被LoaderSample3涓殑瀵硅薄騫跺彲浠ヨ闂叾鍏叡鎴愬憳age銆?br />榪愯鏃跺寘(runtime package)
鐢卞悓涓綾昏杞藉櫒瀹氫箟瑁呰澆鐨勫睘浜庣浉鍚屽寘鐨勭被緇勬垚浜嗚繍琛屾椂鍖咃紝鍐沖畾涓や釜綾繪槸涓嶆槸灞炰簬鍚屼竴涓繍琛屾椂鍖咃紝涓嶄粎瑕佺湅瀹冧滑鐨勫寘鍚嶆槸鍚︾浉鍚岋紝榪樿鐪嬬殑瀹氫箟綾昏杞藉櫒鏄惁鐩稿悓銆傚彧鏈夊睘浜庡悓涓榪愯鏃跺寘鐨勭被鎵嶈兘浜掔浉璁塊棶鍖呭彲瑙佺殑綾誨拰鎴愬憳銆傝繖鏍風殑闄愬埗閬垮厤浜嗙敤鎴瘋嚜宸辯殑浠g爜鍐掑厖鏍稿績綾誨簱鐨勭被璁塊棶鏍稿績綾誨簱鍖呭彲瑙佹垚鍛樼殑鎯呭喌銆傚亣璁劇敤鎴瘋嚜宸卞畾涔変簡涓涓被java.lang.Yes錛屽茍鐢ㄧ敤鎴瘋嚜瀹氫箟鐨勭被瑁呰澆鍣ㄨ杞斤紝鐢變簬java.lang.Yes鍜屾牳蹇冪被搴搄ava.lang.*鐢變笉鍚岀殑瑁呰澆鍣ㄨ杞斤紝瀹冧滑灞炰簬涓嶅悓鐨勮繍琛屾椂鍖咃紝鎵浠ava.lang.Yes涓嶈兘璁塊棶鏍稿績綾誨簱java.lang涓被鐨勫寘鍙鐨勬垚鍛樸?

鎬葷粨
鍛藉悕絀洪棿騫舵病鏈夊畬鍏ㄧ姝㈠睘浜庝笉鍚岀┖闂寸殑綾葷殑浜掔浉璁塊棶錛屽弻浜插鎵樻ā鍨嬪姞寮轟簡Java鐨勫畨鍏紝榪愯鏃跺寘澧炲姞浜嗗鍖呭彲瑙佹垚鍛樼殑淇濇姢銆?/strong>

浜岋紟聽聽聽 鎵╁睍ClassLoader鏂規硶
鎴戜滑鐩殑鏄粠鏈湴鏂囦歡緋葷粺浣跨敤鎴戜滑瀹炵幇鐨勭被瑁呰澆鍣ㄨ杞戒竴涓被銆?strong>涓轟簡鍒涘緩鑷繁鐨勭被瑁呰澆鍣ㄦ垜浠簲璇ユ墿灞?/strong>ClassLoader綾伙紝榪欐槸涓涓娊璞$被銆傛垜浠垱寤轟竴涓?/strong>FileClassLoader extends ClassLoader銆傛垜浠渶瑕佽鐩?/strong>ClassLoader涓殑findClass(String name)鏂規硶錛岃繖涓柟娉曢氳繃綾葷殑鍚嶅瓧鑰屽緱鍒頒竴涓?/strong>Class瀵硅薄銆?/strong>

聽聽聽聽public聽Class聽findClass(String聽name)
聽聽聽聽{
聽聽聽聽聽聽聽聽
byte[]聽data聽=聽loadClassData(name);
聽聽聽聽聽聽聽聽
return聽defineClass(name,聽data,聽0,聽data.length);
聽聽聽聽}


聽聽聽鎴戜滑榪樺簲璇ユ彁渚涗竴涓柟娉昹oadClassData(String name)錛岄氳繃綾葷殑鍚嶇О榪斿洖class鏂囦歡鐨勫瓧
鑺傛暟緇勩傜劧鍚庝嬌鐢–lassLoader鎻愪緵鐨刣efineClass()鏂規硶鎴戜滑灝卞彲浠ヨ繑鍥濩lass瀵硅薄浜嗐?/strong>

聽聽聽聽publicbyte[]聽loadClassData(String聽name)
聽聽聽聽{
聽聽聽聽聽聽聽聽FileInputStream聽fis聽
=null;
聽聽聽聽聽聽聽聽
byte[]聽data聽=null;
聽聽聽聽聽聽聽聽
try
聽聽聽聽聽聽聽聽{
聽聽聽聽聽聽聽聽聽聽聽聽fis聽
=new聽FileInputStream(new聽File(drive聽+聽name聽+聽fileType));
聽聽聽聽聽聽聽聽聽聽聽聽ByteArrayOutputStream聽baos聽
=new聽ByteArrayOutputStream();
聽聽聽聽聽聽聽聽聽聽聽聽
int聽ch聽=0;
聽聽聽聽聽聽聽聽聽聽聽聽
while聽((ch聽=聽fis.read())聽!=-1)
聽聽聽聽聽聽聽聽聽聽聽聽{
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽baos.write(ch);
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽
聽聽聽聽聽聽聽聽聽聽聽聽}
聽聽聽聽聽聽聽聽聽聽聽聽data聽
=聽baos.toByteArray();
聽聽聽聽聽聽聽聽}聽
catch聽(IOException聽e)
聽聽聽聽聽聽聽聽{
聽聽聽聽聽聽聽聽聽聽聽聽e.printStackTrace();
聽聽聽聽聽聽聽聽}
聽聽聽聽聽聽聽聽
聽聽聽聽聽聽聽聽
return聽data;
聽聽聽聽}


鍐嶈璇碢ackage鏉冮檺銆侸ava璇█瑙勫畾錛屽湪鍚屼竴涓寘涓殑class錛屽鏋滄病鏈変慨楗扮錛岄粯璁や負Package鏉冮檺錛屽寘鍐呯殑class閮藉彲浠ヨ闂備絾鏄繖榪樹笉澶熷噯紜傜‘鍒囩殑璇達紝鍙湁鐢卞悓涓涓狢lassLoader瑁呰澆鐨刢lass鎵嶅叿鏈変互涓婄殑Package鏉冮檺銆傛瘮濡傚惎鍔ㄧ被瑁呰澆鍣ㄨ杞戒簡java.lang.String錛岀被璺緞瑁呰澆鍣ㄨ杞戒簡鎴戜滑鑷繁鍐欑殑java.lang.Test錛屽畠浠笉鑳戒簰鐩歌闂鏂瑰叿鏈塒ackage鏉冮檺鐨勬柟娉曘傝繖鏍峰氨闃繪浜嗘伓鎰忎唬鐮佽闂牳蹇冪被鐨凱ackage鏉冮檺鏂規硶銆?/font>




]]>
Bitwise and Bit Shift Operatorshttp://www.tkk7.com/nikita/archive/2009/05/14/270669.htmlpicture talkpicture talkThu, 14 May 2009 09:43:00 GMThttp://www.tkk7.com/nikita/archive/2009/05/14/270669.htmlhttp://www.tkk7.com/nikita/comments/270669.htmlhttp://www.tkk7.com/nikita/archive/2009/05/14/270669.html#Feedback0http://www.tkk7.com/nikita/comments/commentRss/270669.htmlhttp://www.tkk7.com/nikita/services/trackbacks/270669.html Bitwise and Bit Shift Operators
The Java programming language also provides operators that perform bitwise and bit shift operations on integral types. The operators discussed in this section are less commonly used. Therefore, their coverage is brief; the intent is to simply make you aware that these operators exist.

The unary bitwise complement operator "~" inverts a bit pattern; it can be applied to any of the integral types, making every "0" a "1" and every "1" a "0". For example, a byte contains 8 bits; applying this operator to a value whose bit pattern is "00000000" would change its pattern to "11111111".

The signed left shift operator "<<" shifts a bit pattern to the left, and the signed right shift operator ">>" shifts a bit pattern to the right. The bit pattern is given by the left-hand operand, and the number of positions to shift by the right-hand operand. The unsigned right shift operator ">>>" shifts a zero into the leftmost position, while the leftmost position after ">>" depends on sign extension.

The bitwise & operator performs a bitwise AND operation.

The bitwise ^ operator performs a bitwise exclusive OR operation.

The bitwise | operator performs a bitwise inclusive OR operation.

The following program, BitDemo , uses the bitwise AND operator to print the number "2" to standard output.

								class BitDemo {
     public static void main(String[] args) {
          int bitmask = 0x000F;
	  int val = 0x2222;
	  System.out.println(val & bitmask);  // prints "2"
     }

						


]]>
java 瑾跨敤 LINUX service ntpd stop http://www.tkk7.com/nikita/archive/2009/04/26/267540.htmlpicture talkpicture talkSat, 25 Apr 2009 18:38:00 GMThttp://www.tkk7.com/nikita/archive/2009/04/26/267540.htmlhttp://www.tkk7.com/nikita/comments/267540.htmlhttp://www.tkk7.com/nikita/archive/2009/04/26/267540.html#Feedback0http://www.tkk7.com/nikita/comments/commentRss/267540.htmlhttp://www.tkk7.com/nikita/services/trackbacks/267540.htmlIf you read about the Javadoc of the Process class, you will discover something
very weird and unexpected. The following is the context of the Javadoc for Process.
In effect, you should be very clear of this limitation before you think of using
the Process JDK. Ok, here it is:


The methods that create processes may not work well for special processes on certain
native platforms, such as native windowing processes, daemon processes, Win16/DOS
processes on Microsoft Windows, or shell scripts.

The created subprocess does not have its own terminal or console. All its standard
io (i.e. stdin, stdout, stderr) operations will be redirected to the parent process
through three streams (getOutputStream(), getInputStream(), getErrorStream()).
...


So basically, Process does not guarantee your daemon process to work properly. This
is horrifying when I first read about this Javadoc. However, I have changed my
mind after using Process for a while. My experience tells me that usually Process
cannot be working at the following circumstances: (assuming we are in Linux O.S.)

- to execute shell built-in commands e.g. "cd" or "alias"
- to redirect output from the executed application,
- This method will NOT expand filesystem wildcards e.g. "*".

Taking all these things into consideration, let's see what we can do to improve
your code.

First of all, Process has its standard outputstream, and its standard errorstream
(but don't try to redirect them, as it will *not* work)


Process proc = Runtime.getRuntime().exec(command);

// Create thread for reading inputStream (process' stdout)
proc.getInputStream();

// Create thread for reading errorStream (process' stderr)
proc.getErrorStream()


Another fact I can see why your ntpd has not stopped is maybe you havn't given
enough time for the Process to be executed completely.

Consider adding the following code into your program:


// this will wait for the process to end!!! I think it is very important
// not to interfere with other process in the O.S.
int returnCode = proc.waitFor();

String msg = "Shell command [" + commandString + "] result [";
if (returnCode == 0)
{
msg += "SUCCEEDED";
}
else
{
msg = msg + "FAILED - ret code: " + returnCode;
}
msg += "]";



Then you can print the msg to the standard output or simply trace it into your log.
You shall see the error if occurs.

Another thing I can suggest you to do is fully read the Process Javadoc and any related documents about using Process.

Hope these help.


import java.io.*;
public chass shell{
public static void main(String [] args)throws Exception{
try

{

process = Runtime.getRuntime().exec ("bin/sh service ntpd stop");

InputStreamReader ir=newInputStreamReader(process.getInputStream());

LineNumberReader input = new LineNumberReader (ir);


String line;

while ((line = input.readLine ()) != null)

System.out.println(line);

}

catch (java.io.IOException e){

System.err.println ("IOException " + e.getMessage());

}
}

鏉ヨ嚜 :http://www.cjsdn.net/post/view?bid=1&id=196586


]]>
主站蜘蛛池模板: 一区二区在线免费观看| 一级女人18毛片免费| 99久久亚洲综合精品成人网| 无码永久免费AV网站| 色吊丝免费观看网站| 亚洲成人精品久久| 国产精品国产免费无码专区不卡| 国产成人无码免费网站| 亚洲欧洲在线播放| 亚洲情侣偷拍精品| 永久免费毛片在线播放| 无遮挡国产高潮视频免费观看| 亚洲精品日韩专区silk| 免费一看一级毛片人| 97公开免费视频| 一个人看的hd免费视频| 亚洲免费黄色网址| 亚洲色无码专区在线观看| 成人看的午夜免费毛片| 在线观看黄片免费入口不卡| 亚洲欧美aⅴ在线资源| 久久久综合亚洲色一区二区三区 | 亚洲av纯肉无码精品动漫| 亚洲色中文字幕无码AV| 日本免费的一级v一片| 亚洲啪啪免费视频| 国产又黄又爽又大的免费视频| 亚洲精品国产日韩| 亚洲网址在线观看你懂的| 国产精品xxxx国产喷水亚洲国产精品无码久久一区 | 亚洲午夜久久久久久久久电影网| 麻豆国产VA免费精品高清在线| 一级毛片在线观看免费| 皇色在线免费视频| 免费国产黄网站在线看| 亚洲成a人片在线观看天堂无码| 久久99亚洲网美利坚合众国 | 成人亚洲综合天堂| 免费看大美女大黄大色| 少妇高潮太爽了在线观看免费| 国产成人AV片无码免费|