Quick Search


Tibetan singing bowl music,sound healing, remove negative energy.

528hz solfreggio music -  Attract Wealth and Abundance, Manifest Money and Increase Luck



 
Your forum announcement here!

  Free Advertising Forums | Free Advertising Board | Post Free Ads Forum | Free Advertising Forums Directory | Best Free Advertising Methods | Advertising Forums > Free Advertising Forums Directory > Message Boards Directory

Message Boards Directory These are similar to forums, but the posts are listed in chronological order and not by category. They also dont require any registration.

Reply
 
Thread Tools Search this Thread Display Modes
Old 03-27-2011, 09:10 AM   #1
ming6bai8d
Second Lieutenant
 
Join Date: Feb 2011
Posts: 415
ming6bai8d is on a distinguished road
Default

| Back to logs list

Reprinted from 304510237 at 10:37 on July 23, 2010 Reading (loading. ..) Comments (0) Category: Technical Articles
down here not to discuss the application of single-case model what occasion, the main delay is that caused by loading a series of single-case model, as well as how to solve.
the following delay load problem on the analysis of reference from:


the above mentioned model of delay in loading a single case double-checked locking (referred to DCL), ie double lock failed, and the solutions for the DCL.

first look at the delay of loading a single case code:


synchronized block around the creation of the single object case, it seems that the delay is a typical load singleton pattern. But there is a problem, assume that thread A is running to / / 1 when thread B is preempted the cpu, and run to / / 3, then thread A will continue to repeat to create objects, leading to the destruction of a single cases of rules.
ok, then we do a modification, the code becomes this:
we see that, in addition to / / 1 for a non-null check in the synchronized block of code / / 3 and added a check, which is double-checked locking (DCL), so as to avoid the above other threads to create singleton objects repeated the question, looks like perfect.
Unfortunately, even the DCL may also fail.
instance = new Singleton ();
simple line of code to create the object to be divided into steps:
1) Allocate memory,
2) invoke constructor,
3) give reference
If this is the order of steps 1), 2), 3) that no problem, but the JIT compiler does not guarantee 2) and 3) order, so may become a 1), 3), 2) Then take a look at what might happen:
thread A first enter the synchronized block, the implementation instance = new Singleton (), then instance only to get a ref, but the constructor has not yet implemented, to exit the synchronization block;
Cut the thread B, then a non-null instance of (the above thread has been assigned A ref), then to return the instance, and this instance is not initialized by constructor, and then access the instance will cause an error.
This is JITcompilers the out-of-order issue, led to the order of initialization and unpredictable variable assignment, resulting in more problems.
more detailed analysis on the DCL:



Well, to all the problems listed here,paul smith wallets sale, and have been able to see the singleton pattern has become so cumbersome to use delay loading and worrying.
first load delay aside, for the singleton, if the do not care whether the delay must be loaded, the easiest way is nothing less than the static load:

do both easy and safe.

or delay to see how to improve the singleton pattern is loaded:

only call the getInstance method, using LazyFoo class, will initialize the LazyFoo, also reached the purpose of lazy, but not jdk5.
ming6bai8d is offline   Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off


All times are GMT. The time now is 11:43 AM.

 

Powered by vBulletin Version 3.6.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Free Advertising Forums | Free Advertising Message Boards | Post Free Ads Forum