I was writing a chat program on LAN last night , I defined a Map Class properties of type , Saves the mapping between the user nickname and the server output stream . Then I call the class properties on the server side on the client side . The program runs in a mess . I finally looked for it for a long time , Tested in different places with output statements for a long time ( The key is to use eclipse Of DUBUG When , It doesn't seem to work ). Finally, it's locked in
The client calls the class property on the server side
something the matter . I can't get the value , The output is null. Why is that ? In the end, I wrote two other test programs to test the static properties in two different programs , Can data be shared .

Define first work class , There are static properties in it b

public class work { public static int b =2; public static void main(String[]
args) { System.out.println(b); b=5; } }
Then define Test class , stay Test In the main method of class , Output first b Value of , Again b Make changes .

public class Test { public static void main(String[] args) {
System.out.println(work.b); work.b=7; } }
Now I run Test program , The output is 2, This is what I expected . The key is to run the second program work Time , Member variables of the output class of the program b Value of , What is the value of this property ? The result is still 2, Instead of our revised 7.

What's going on ? Why not 7 ah ? No, it's not , Do the static attributes of all instances of the same class share the same block of memory ? First run Test Static properties changed during program b Value of , So run the program for the second time work Time ,b Attributes are also affected ! This problem bothered me all night . Time after the test ,12 It's half past three . It's late , Wash and sleep , Check more information tomorrow . So with this question , I went to bed .

In the morning , Decisively opened the madness javaPDF edition . Start searching for answers . finally , keep thy shop and thy shop will keep thee. , I found it .
It's because of running Test and work Twice JVM process , for the first time JVM After operation , It's right work All changes made by the class will be lost --- Second operation JVM Will be initialized again A class . That is to say , Two programs are in two different JVM In progress , Two JVM Data is not shared between

It's like the programmer solved it BUG It's exciting , I found the problem , And excited . Just write down an article , In case of similar problems for yourself or others , Baidu is not there . tell the truth , I don't know how to deal with this problem , How to describe . Actually, I met this problem , I'm very happy , Because I found out what I didn't know , I think that's how programmers grow , Find answers to questions , Growing knowledge in search of answers . How to solve my LAN chat problem , I have to think about it . hey , The way of programming , A long way to go .

©2019-2020 Toolsou All rights reserved,
C Language programming to find a student's grade java Realize the function of grabbing red packets Random forest R Language implementation QCustomPlot series (5)- Real time dynamic curve Software testing BUG describe use C++ I want to talk to you “ Prototype mode ” ( copy / copy constructor )JS How to operate China's longest high speed rail officially opened ! The fastest way to finish the race 30.5 hour Zimi apologizes :33W Gan charger delayed due to force majeure 2021 year 2 Chinese programming language ranking