// data object we want to retain private MyDataObject data;
// this method is only called once for this fragment @Override publicvoidonCreate(Bundle savedInstanceState){ super.onCreate(savedInstanceState); // retain this fragment setRetainInstance(true); }
// find the retained fragment on activity restarts FragmentManager fm = getFragmentManager(); dataFragment = (DataFragment) fm.findFragmentByTag(“data”);
// create the fragment and data the first time if (dataFragment == null) { // add the fragment dataFragment = new DataFragment(); fm.beginTransaction().add(dataFragment, “data”).commit(); // load the data from the web dataFragment.setData(loadMyData()); }
// the data is available in dataFragment.getData() ... }
@Override publicvoidonDestroy(){ super.onDestroy(); // store the data in the fragment dataFragment.setData(collectMyLoadedData()); } }
You’ve started the Django development server, a lightweight Web server writtenpurely in Python. We’ve included this with Django so you can develop thingsrapidly, without having to deal with configuring a production server – such asApache – until you’re ready for production.
publicclassMain { publicstaticvoidmain(String[] args)throws InterruptedException { First first = new First(); Second second = new Second(first); synchronized( second ) { System.out.println("I'm faster than second~"); second.notifyAll(); } } }
publicclassMain { publicstaticvoidmain(String[] args)throws InterruptedException { First first = new First(); Second second = new Second(first); System.out.println("wating for all threads prepared~"); Thread.sleep(2000); synchronized( second ) { System.out.println("I'm faster than second~"); second.notifyAll(); } } }
输出结果:
1 2 3 4
wating for all threads prepared~ I’m faster than second~ I’m faster than first~ hello world~