Replacement for PhaseListener in RAP 3.0 - execute code on the UI thread
Hello,
we've used a PhaseListener to open/close a database connection for each request.
The database connection is tied to the current UI thread.
Do you have any suggestion how to realize this without using a phase listener in RAP 3.0?
I've tried to use a MessageFilter but the handleMessage method is not executed on the UI thread.
Thank you,
Ken
Hi Ralf,
thank you for the explanation.
We actually do not open a connection for each request. We just start a "unit of work" for the current thread that is able to track the database connections that are created on demand. This unit of work (and hence the underlying connections) is closed after a request.
Now the problem is that we need to execute the code that starts and stops the unit of work within the UI thread. This is due to the fact that our model objects (that are displayed by JFace viewers for example) are bound to an entity manager that requires an active unit of work for the current thread to open an underlying database connection.
I don't see any other solutions as using a phase listener for the start and stop events of the UI thread or starting/stopping the unit of work for any individual interaction with the model objects. It is practically impossible to implement the latter in a clean way.
Any comments or suggestions are welcome.
Best regards,
Ken
Similar Messages
-
iPhone 4 won't slide to unlock . I tried everything possible and even got my phone replaced fora new one costing me 10,282 Rupees . The new phone is again having the same problem even without adding any apps or taking data backup
Yeah, first my thought was also that... that's why I've gone to Apple and they already switched the phone twice!!!
Last time was yesterday... I posted this here because I came from Apple and with a new iPhone 5, although I didn't restore anything from iCloud, I hadn't even logged in to iCloud / AppStore, and without any event on the lockscreen my iPhone 5 was already "locked" on the unlock screen... after a mere 45m after I used it without a single App!! Just a couple of SMS / 1 or 2 calls... I'm going to Apple again on monday, but tried to post here to see if this has happened before to anyone with 3 new iPhones!!! -
The request to execute code in the sandbox failed
I have developed a webpart for a client which is hosted on
O365.
While saving the webpart properties I am Getting the error"Web Part Error: The request to execute code in the sandbox failed."
The same web part works on a different O365 site perfectly fine.Try below article
http://social.msdn.microsoft.com/Forums/sharepoint/en-US/70b13a7f-c9f8-4bf9-8229-670472959e60/web-part-error-sandboxed-code-execution-request-failed?forum=sharepointdevelopmentprevious -
I wondered if anyone else also got a tiny replacement that was not really like for like. Or am I the only one?
Because it is smaller it is not like for like?
Sell it on the open market, lots of people are looking for refurbished Generation 6 Nanos.
See what I mean: https://discussions.apple.com/thread/4750990?tstart=0
Message was edited by: deggie -
Generate, compile, load, execute code on-the-fly
Hi,
I'd like to make something that:
- 1) Generates Java source code (this I can do)
- 2) Compiles this generated source code (I found an unsatisfying solution)
- 3) Loads the newly created classes (I'm stuck here)
- 4) Executes them in this very same program. (That should be trivial once the classes are loaded)
The solution I found for 2) is to invoke the compiler through Runtime.exec(). Isn't there a more integrated solution ?
And for 3), I think there is something to do with a ClassLoader or so, I'll try to figure it out on my own in the meantime.
Thank you,
The Ultimate Koalasee maybe Jakarta BCEL on : http://jakarta.apache.org/bcel/index.html and : http://jakarta.apache.org/bcel/manual.html (Byte Code Engineering Library)
-
Replacement for 'WS_MSG'
Hi All,
Can anyone suggest a replacement for obsolete FM "WS_MSG".?
Thanks ,
VasukiRefer to the below thread -
is 'POPUP_TO_DISPLAY_TEXT' obsolete ..if so how to check
Please refer to the earlier threads in the Forum before posting a new thread. -
Replacements for FS and Marshall Muffler cases
My students have previously taken an ERP course that included the Mueili Simulation Game. In the next course, I had them do the Fitter Snaker configuration exercises followed by the Marshal Muffler case. Now, it seems that the Fitter Snack configuration series of exercies will no longer be available, and is being replaced by the Global BIke case -- yet, I cannot find any material for the Global Bike case -- when is it to be avaiable?
Also, the Marshall Muffler case does not seem to be available either -- I cannot find a reference to it in the UA site. If it is no longer available, what is a good replacement for it? I have not yet looked at the Kite case to see if it is a good candidate to replace Fitter Snacker or Marshall Muffler.
What I would like is a series of exercises that takes students through some configuraiton, and then forecasting, production, purchasing, selling (like the Fitter Snaker configuration). After that, I would like them to do another case without detaied instructions to do some configuraiton, produciton, purchasing, sellling (like Marshall Muffler).
The BPI series of exercises might do some of the above.
Thanks for any suggestions.The Marshall Muffler case is still available along with all of the otherFitter Snacker configuration materials. Navigate to:
https://cw.sdn.sap.com/community/uac/bpm
Then scroll down to Fitter Snacker configuration and download that material.
I will be providing a modified module 12 document for the community network shortly. There are a couple of fixes needed for the ECC 6.0 version that I didn't catch the first time I revised the documents. -
Where i can get replacement for my cinema display 65W power adapter?
Hi, who can tell me where i can get replacement for my cinema display 65W power adapter?
If the display uses the Apple Display Connector (ADC)
<http://upload.wikimedia.org/wikipedia/commons/thumb/0/09/AppleDisplayConnector.j pg/800px-AppleDisplayConnector.jpg>
you will need a DVI to ADC adapter.
<http://www.welovemacs.com/mb571zla.html>
They are also available on eBay.
<http://www.ebay.com/itm/Apple-DVI-to-ADC-adapter-A1006-for-Apple-LCD-monitors-Mi nt-Condition-/251073546040?pt=US_Video_Cables_Adapters&hash=item3a75264738#ht_50 0wt_1089> -
Adf valueChangeListener autosubmit=true, execute code after update model
Hello.
I'm working with the valueChangeListener and autosubmit="true". I'll try to explain my situation
with an example.
jsp:
<af:form>
<af:panelForm>
<af:inputText
id="value1"
label="Value1"
value="#{index.myObject.value1}"
autoSubmit="true"
valueChangeListener="#{index.changeListener1}"/>
<af:inputText
id="value2"
label="Value2"
value="#{index.myObject.value2}"/>
</af:panelForm>
</af:form>
backing:
public class Index {
private MyObject myObject;
public Index() {
myObject = new MyObject();
public void changeListener1(ValueChangeEvent valueChangeEvent){
doSomethingWithMyObject(myObject);
// ... get/set of myObject
MyObject:
public class MyObject {
private String value1;
private String value2;
public MyObject() {}
//getters/setters...
}In the line doSomethingWithMyObject(myObject) i need myObject with the actual values in the user form.
in the example above, the first time the page is rendered and shows the inputs
if the user captures something in the 1st input and then hits the tab to go to the other input
the valueChangeEvent is fired, and the code in "index.changeListener1" executed, but at this moment
the model (myObject) hasn't been updated with the data that the user entered (Validation Phase).
So i need a way to execute my code called from the "valueChangeEvent" but after the model has been updated
Some notes about my problem:
- The doSomethingWithMyObject(myObject) could update data in myObject
- About binding="#{x.y}":
I know i can use the binding attribute in the tag <af:inputText binding="#{x.y}"> and then in the code of
the changelistener the binded component always have the most recent value from the user,
but i cant' use that, the method needs a MyObject instance.
- I don't think create a new instance of MyObject and populate it every time the event fires is a good way
- doSomethingWithMyObject" is a black box, so i don't know what is going to do with myObject
- In my problem there are more than 2 inputs there will be N components M listeners.
What I'm trying:
PhaseListener:
I have been implementing a solution with a PhaseListener like
public void afterPhase(PhaseEvent phaseEvent) {
// just after UPDATE_MODEL_VALUES phase
FacesContext f = FacesContext.getCurrentInstance();
Index i = (Index) f.getApplication().createValueBinding("#{index}").getValue(f);
// at this point the model is updated
doSomethingWithMyObject(i.getMyObject);
public PhaseId getPhaseId() {
return PhaseId.UPDATE_MODEL_VALUES;
this works but i don't know if this is the answer according to this post (unanswered at this time):
http://forums.oracle.com/forums/thread.jspa?threadID=611643
says something about that PhaseListener is not thread safe and blocks the application with more
than 1 user.
A wrapper:
using the controls binded to the backing
public class Index {
private MyObject myObject;
private CoreInputText inputValue1;
private CoreInputText inputValue2;
//listener
//getters/setters
} make a wraper like
public class MyObjectW {
private Index index; // wrap the backing index
public MyObjectW(Index index) {
this.index = index;
public String getValue1(){
return (String) index.getInputValue1().getValue();
public String getValue2(){
return (String) index.getInputValue2().getValue();
public void setValue1(Object v){
index.getInputValue1().setValue(v);
public void setValue2(Object v){
index.getInputValue2().setValue(v);
}and then call in the index backing:
doSomethingWithMyObject( new MyObjectW(this)); so it will access to the most actual values from user at the valueChangeEvent
But i really would like some way to execute my code called from the "valueChangeEvent" but after the model has been updated
so i dont need to wrap or implement PhaseListener
what do you think, what do you suggest, have any solution or a way to do what I'm trying?
thank you for your help...
Message was edited by:
akanewstedHello Frank, thanks for the response.
When you say
"If you need an updated object in this listener then you can update it from the value change listener as well"
you mean i can update the object by myself with the value from getNewValue()? or is there another way
to call to update the models at this time ?
I know i have the methods "getOldValue()" and "getNewValue()" in the "ValueChangeEvent" but what if i need
the actual value from the user in other control than the one that fires the event
example
Two inputs:
in the input1 the user enters some data
in the input2 when some data is entered it fires valueChangeListener (autosubmit=true)
in that case what if i need the value the user just entered in the input1 in the valueChangeListener of
the input2.
In general the app I'm working must do:
dynamically generate the controls in the form (inputs, selects etc)
Attach the control values to a model ( <af:inputText value=#{model.x}"/>
sometimes execute some script when a value change in a control (valueChangeListener)
those scripts uses the model (and needs to be an updated model)
script = " if (value2 = 'xyz') then value1='abc'; return true;";
if the model is not updated
the script will use old values and will be wrong
or if the script change some value in the model, when the update model phase occurs the value from
the script is lost.
that's why i need to work directly with the model and not the values in the ValueChangeEvent
Is there a way to use something like an action in the change of a control value?
that way the code will execute in the invoke application phase, can this be done ?
how i can execute code in the invoke application when a valueChangeEvent occurs ?
hope this help to explain more my situation.
Thank you for your help and time. -
Double Factory pattern purposal as replacement for Double Check #2
Hi All,
Here is the code for the pattern proposal, its intended as a replacement for double checked locking, which was proved to be broken in 2001. Here is the code...
public class DoubleFactory {
private static Object second_reference = null;
public static Object getInstance() {
Object toRet = second_reference;
if (toRet == null) {
second_reference = CreationFactory.createInstance();
toRet = second_reference;
return toRet;
private DoubleFactory() {}
public class CreationFactory {
private static Object instance = null;
public static synchronized Object createInstance() {
if (instance == null) {
instance = new Object();
return instance;
}Also I have spent several months discussing this with Peter Haggar, who believes that this code is not guaranteed to work. However I have been unable to discern from his message why he believes this will not be guaranteed to work, and I am posting this here to attempt to find a clearer explanation or confirmation that the pattern I am purposing (Double Factory) is guaranteed to work.
Thanks,
Scott
---------------------------- Original Message ----------------------------
Subject: Re: [Fwd: Double Factory replacement for Double Check #2] From:
"Scott Morgan" <[email protected]>
Date: Fri, January 25, 2008 10:36 pm
To: "Peter Haggar" <[email protected]>
Hi Peter,
I appologize if my last response came accross as rude or something. If
my code is not guaranteed to work ok, can you help me understand why. I
am after all looking for a solution for all of us.
If my solution is wrong as you say because the member variables of the
singleton are not up to date. I understand this to mean that the
second_reference pointer is assigned to the memory where the instance
object will get created before the instance object even starts the
creation process (when the jvm allocates memory and then enters the
constructor method of the Singleton). This doesn't seem possible to me.
Can you refrase your statments, to help me understand your points?
If not I am happy to turn to the original wiki for discussion.
Thanks for your effort,
Scott
Thanks for asking my opinion, many times, then telling me I'm
wrong...wonderful. You are a piece of work my friend. For what it'sworth, your email below shows you still don't understand these issues
or what I was saying in my emails. I've been more than patient.
>
All the best. And by the way, your code is not guaranteed to work. It's not just me that's "wrong", it's also the engineers at Sun who
designed Java, the JVM, and the memory model, and countless people who
have studied it. I'm glad you have it all figured out.
>
Peter
"Scott Morgan" <[email protected]>
01/18/2008 12:47 PM
Please respond to
[email protected]
To
Peter Haggar/Raleigh/IBM@IBMUS
cc
Subject
Re: [Fwd: Double Factory replacement for Double Check #2]
Hi Peter,
Thanks I understand your position now. However am I still believe that
it will work and be safe;
1) the Singleton you show would be fully constructed (having exited theSingleton() method) before the createInstance() method would have
returned.
2) The second_reference could not be assigned until the createInstance()
method returns.
3) So by the time second_reference points to Singleton all of the valueswill be set.
>
>
I do understand that if the createInstance method was not synchronized(at the CreationFactory class level) that my logic would be flawed, but
since there is synchronization on that method these points are true, and
your comments about up-to-date values are not accurate.
>
Cheers,
Scott
>In your listing from your latest email T2 does encounter a sync block
on createInstance.
>>>>
No. T2 will call getInstance and see second_reference as non-null.second_reference was made non-null by T1.
>>
>>>>
What are you exactly are you refering to with the phrase 'up-to-datevalues'?
>>>>
Assume my singleton ctor is thus:
public class Singleton
private int i;
private long l;
private String str;
public Singleton()
i = 5;
l = 10;
str = "Hello";
T2 will get a reference to the Singleton object. However, because youaccess second_reference without synchronization it may not see i as 5,
l as 10 and str as "Hello". It may see any of them as 0 or null. This
is not the out of order write problem, but is a general visibility
problem because you are accessing a variable without proper
synchronization.
>>
Peter
"Scott Morgan" <[email protected]>
01/16/2008 11:38 PM
Please respond to
[email protected]
To
Peter Haggar/Raleigh/IBM@IBMUS
cc
Subject
Re: [Fwd: Double Factory replacement for Double Check #2]
Hi Peter,
In your listing from your latest email T2 does encounter a sync blockon createInstance.
>>
What are you exactly are you refering to with the phrase 'up-to-datevalues'?
In this code the Singleton should also be
A) non mutable (as in the instance of class Object in the example).
If the singleton was more complex then the code to populate it'svalues
would go inside the sync of createInstance().
B) mutable with synchronization on it's mutator methods.
In your article you mention out of order writes, which doesn't occurin
this code.
Cheers,
Scott
You read it wrong.
- T1 calls getInstance which in turn calls createInstance.
- T1 constructs the singleton in createInstance and returns to
getInstance.
- T1 sets second_reference to the singleton returned in getInstance. -T1 goes about its business.
- T2 calls createInstance.
- T2 sees second_reference as non-null and returns it
- Since T2 accessed second_reference without sync, there is noguarantee
that T2 will see the up-to-date values for what this object refers to.
- Therefore the code is not guaranteed to work.
>>>
If this is not clear:
- Re-read my email below
- Re-read my article
- If still not clear, google on Double Checked Locking and readanything
from Brian Goetz or Bill Pugh.
Peter
"Scott Morgan" <[email protected]>
01/13/2008 05:26 AM
Please respond to
[email protected]
To
Peter Haggar/Raleigh/IBM@IBMUS
cc
Subject
Re: [Fwd: Double Factory replacement for Double Check #2]
Hi Peter,
Thanks for the reply, I don't see how T2 would see the a referenceto
a
partialy initialized object before the createInstance() method had
returned. If T1 was in createInstance() when T2 entered
getInstance(), T2 would wait on the CreationFactory's class monitor to
wait to enter createInstance().
Or in other words in the line of code ....
second_reference = CreationFactory.createInstance();
The pointer second_reference couldn't be assigned to the singleton
instance when the synchronized createInstance() had fully constructed,initialized and returned the singleton instance. Before that the the
second_reference pointer would always be assigned to null. So any
thread entering getInstance() before createInstance() had returned
(for the first time) would wait on the CreationFactory's class monitor
and enter the createInstance() method.
>>>
So T2 will wait for T1.
Cheers,
Scott
PS I think I am writing requirements for my next project :)
Sorry for the delay...been in all day meetings this week.
You are correct...I had been reading your code wrong, my apologies.
My explanations, although correct, did not exactly correspond to your
code.
However, the code is still not guaranteed to work. Here's why:
Assume T1 calls getInstance() which calls createInstance() and returnsthe
singelton. It then sets second_reference to refer to that singleton.
So
far, so good. Now, T2 executes and calls getInstance(). It can see
second_reference as non-null, so it simply returns it. But, there
was
no
synchronization in T2's code path. So there's no guarantee that even
if
T2 sees an up-to-date value for the reference, that it will seeup-to-date
values for anything else, ie what the object refers to...it's
instance data. If T2 used synchronization, it would ensure that it
read
up-to-date
values when it obtained the lock. Because it didn't, it could see
stale
values for the object's fields, which means it could see a partially
constructed object.
>>>>
In the typical double-checked locking, the mistake is to assume theworst
case is that two threads could race to initialize the object. But
the worst case is actually far worse -- that a thread uses an object
which
it
believes to be "fully baked" but which is in fact not.
Peter
"Scott Morgan" <[email protected]>
01/03/2008 06:33 PM
Please respond to
[email protected]
To
Peter Haggar/Raleigh/IBM@IBMUS
cc
Subject
Re: [Fwd: Double Factory replacement for Double Check #2]
Hi Peter,
Thanks for responding, I am still thinking that your mis
interpreting
the code so I have rewritten it here (Replacing
DoubleFactory.instance with DoubleFactory.second_reference for
clarity). If the T1 burps (gets interrupted) in the createInstance
method it wouldn't have returned so the second_reference pointer
would have never been
assigned
so T2 would just try again upon entering the getInstance method. Orif
it had already entered getInstance it would be waiting to enter
(until T1 releases the lock on CreationFactory.class ) on the
createInstance method.
>>>>
public class DoubleFactory {
private static Object second_reference = null;
public static Object getInstance() {
Object toRet = second_reference;
if (toRet == null) {
second_reference =
CreationFactory.createInstance();
toRet = second_reference;
return toRet;
private DoubleFactory() {}
public class CreationFactory {
private static Object instance = null;
public static synchronized Object createInstance() {
if (instance == null) {
instance = new Object();
return instance;
Does this clear up my idea at all?
second_reference should be always pointing to
null
or
a fully initialized Object
(also referenced by the pointer named 'instance' ), I don't see howit would end up partially initialized.
>>>>
Thanks Again,
Scott
"It" refers to T2.
Your createInstance method is identical to my Listing 2 and is fine
and
will work.
Yes, the problem with your code is in getInstance.
>I don't see how the DoubleFactory getInstance method could bereturning
a partially initialized object at this point. If CreationFactoryalways
returns a fully initialized object and DoubleFactory only assigns a
new
reference/pointer to it how could DoubleFactory getInstance return a
reference/pointer to partially initialized object?
>>>>>>>
>>>>>
The reason it is not guaranteed to work is explained in my previousemails
and in detail in the article. However, I'll try again. Anytime you
access shared variables from multiple threads without proper
synchronization, your code is not guaranteed to work. Threads are
allowed
to keep private working memory separate from main memory. There are
2
distinct points where private working memory is reconciled with main
memory:
- When using a synchronized method or block - on acquisition of thelock
and when it is released.
- If the variable is declared volatile - on each read or write of
that
volatile variable. (Note, this was broken in pre 1.5 JVMs which isthe
reason for the caveat I previously mentioned)
Your createInstance method uses synchronization, therefore, the
reconciliation happens on lock acquisition and lock release. T1 can
acquire the lock in createInstance, make some updates (ie create an
object, run it's ctor etc), but then get interrupted before exiting
createInstance and therefore before releasing the lock. Therefore,
T1
has
not released the lock and reconciled its private working memory withmain
memory. Therefore, you have ZERO guarantee about the state of mainmemory
from another threads perspective. Now, T2 comes along and accesses
"instance" from main memory in your getInstance method. What will
T2
see?
Since it is not properly synchronized, you cannot guarantee that T2sees
the values that T1 is working with since T1 may not have completely
flushed its private working memory back to main memory. Maybe it
did completely flush it, maybe it didn't. Since T1 still hold the
lock,
you
cannot guarantee what has transpired. Maybe your JVM is not usingprivate
working memory. However, maybe the JVM your code runs on does or
will
some day.
Bottom line: Your code is not properly synchronized and is notguaranteed
to work. I hope this helps.
Peter
"Scott Morgan" <[email protected]>
01/03/2008 12:49 PM
Please respond to
[email protected]
To
Peter Haggar/Raleigh/IBM@IBMUS
cc
Subject
Re: [Fwd: Double Factory replacement for Double Check #2]
Hi Peter,
Thanks for your response, I don't follow what 'it' refers to in
the
phrase 'It can see'. So for the same reason that you state that
example 2 from your article I believe this class CreationFactory to
work flawlessly when a client object calls the createInstance
method.
>>>>>
I see this CreationFactory code as identical to your example 2 doyou agree with this?
>>>>>
public class CreationFactory {
private static Object instance = null;
public static synchronized Object createInstance() {
if (instance == null) {
instance = new Object();
return instance;
}Then my rational in the DoubleFactory class is that it can obtain a
reference/pointer to the fully initialized object returned bycalling the above code. I believe you think that the problem with
my code is
in
the DoubleFactorys getInstance method, is this correct?
I don't see how the DoubleFactory getInstance method could bereturning
a partially initialized object at this point. If CreationFactory
always
returns a fully initialized object and DoubleFactory only assigns a
new
reference/pointer to it how could DoubleFactory getInstance return a
reference/pointer to partially initialized object?
>>>>>
Thanks again,
Scott
public static synchronized Singleton getInstance() //0
if (instance == null) //1
instance = new Singleton(); //2
return instance; //3
This above code is fine and will work flawlessly.
Annotating my paragraph:
T1 calls getInstance() and obtains the class lock at //0. T1 "sees"
instance as null at //1 and therefore executes: instance = new
Singleton() at //2. Now, instance = new Singleton() is made up of
several lines of non-atomic code. Therefore, T1 could be
interrupted
after Singleton is created but before Singleton's ctor isrun...somewhere
before all of //2 completes. T1 could also be interrupted after
//2 completes, but before exiting the method at //3. Since T1 has
not
exited
its synchronized block it has not flushed its cache. Now assume T2
then
calls getInstance().
All still true to this point. However, with your code the nextparagraph
is possible, with the code above, it's not. The reason is that T2
would
never enter getInstance() above at //0 because T1 holds the lock. T2will
block until T1 exits and flushes it's cache. Therefore, the code
above
is
properly thread safe.
It can "see" instance to be non-null and thus
return it. It will return a valid object, but one in which its ctor
has
not yet run or an object whose
values have not all been fully flushed since T1 has not exited itssync
block.
"Scott Morgan" <[email protected]>
01/02/2008 06:10 PM
Please respond to
[email protected]
To
Peter Haggar/Raleigh/IBM@IBMUS
cc
Subject
Re: [Fwd: Double Factory replacement for Double Check #2]
Hi Peter,
Thanks for the response I understand the rational for inventing
the
double check anti pattern, I am sorry I still don't understand the
difference between your solution #2 and my CreationFactory class.
>>>>>>
From your article figure 2.public static synchronized Singleton getInstance() //0
if (instance == null) //1
instance = new Singleton(); //2
return instance; //3
If I understand your email correctly this figure 2 is also flawed,since...
>>>>>>
T1 calls getInstance() and obtains the class lock at //0. T1 "sees"
instance as null at //1 and therefore executes: instance = new
Singleton() at //2. Now, instance = new Singleton() is made up ofseveral lines of non-atomic code. Therefore, T1 could be
interrupted
after Singleton is created but before Singleton's ctor isrun...somewhere
before all of //2 completes. T1 could also be interrupted after
//2 completes, but before exiting the method at //3. Since T1 has
not
exited
its synchronized block it has not flushed its cache. Now assume T2
then
calls getInstance(). It can "see" instance to be non-null and thus
return it. It will return a valid object, but one in which its
ctor
has
not yet run or an object whose
values have not all been fully flushed since T1 has not exited itssync
block.
So is #2 is also flawed for this reason?
If so please revise your article, since I interpreted #2 as a
plausible
solution recommended by you (which lead me to the DoubleFactory
idea).
If not please help me understand the difference between #2 and my
CreationFactory class.
>>>>>>
Thanks,
Scott
#2 is in Listing 2 in the article. What I meant was to forget the
DCL
idiom, and just synchronize the method...that's what listing 2
shows.
DCL
was invented to attempt to get rid of the synchronization for 99.9%
of
the
accesses.
The solution I outlined in my email is using the DCL idiom, but on
a
1.5
or later JVM and using volatile.
You solution is not guaranteed to work. Here's why:
public class DoubleFactory {
private static Object instance = null;
public static Object getInstance() {
Object toRet = instance;
if (toRet == null) {
instance =
CreationFactory.createInstance();
toRet = instance;
return toRet;
private DoubleFactory() {}
public class CreationFactory {
private static Object instance = null;
public static synchronized ObjectcreateInstance()
//1
if (instance == null) {
instance = new Object(); //2
return instance;
} //3
}T1 calls createInstance() and obtains the class lock at //1. T1"sees"
instance as null and therefore executes: instance = new Object() at//2.
Now, instance = new Object() is made up of several lines of
non-atomic
code. Therefore, T1 could be interrupted after Object is created
but
before Object's ctor is run...somewhere before all of //2
completes.
T1
could also be interrupted after //2 completes, but before exiting
the
method at //3. Since T1 has not exited its synchronized block ithas
not
flushed its cache. Now assume T2 then calls getInstance(). It can"see"
instance to be non-null and thus return it. It will return a
valid object, but one in which its ctor has not yet run or an
object
whose
values have not all been fully flushed since T1 has not exited itssync
block.
The bottom line is that if you are accessing shared variables
between
multiple threads without proper protection, you are open for aproblem.
Proper protection is defined as: proper synchronization pre 1.5,
and
proper synchronization or proper use of volatile 1.5 or after.
Therefore, if you must use the DCL idiom you have one option: -
Use DCL with volatile on a 1.5 or later JVM.
>>>>>>>
You can also forget about DCL and just use synchronization (listing2
in
my article) or use a static field (listing 10 in my article).
I hope this clears it up.
Peter
"Scott Morgan" <[email protected]>
01/02/2008 04:00 PM
Please respond to
[email protected]
To
Peter Haggar/Raleigh/IBM@IBMUS
cc
Subject
Re: [Fwd: Double Factory replacement for Double Check #2]
Hi Peter,
I apologies for not understanding but I don't see what is
different
between the solution you purposed...
2) Don't use DCL but use synchronization
and the code that I am putting forward. Perhaps I do just notunderstand
but you seem to be contradicting yourself in this email?
I understand that you are saying in #2 that this will always 'work'
with
out any issues...
public static Object instance = null;
public static synchronized Object getInstance() {
if (instance == null) {
instance = new Object();
return instance;
But first you seem to say in the email that if T1 gets
interrupted
it
may leave the instance pointing to a partially initialized object?
So as far as I understand it the createInstance method in my
CreationFactory class should be successful (always retuning a
fully initialized object) for the same reason #2 is successful.
Please keep in mind that there are two different instancepointers
in
the code I sent you, one is part of the DoubleFactory class and
the other is part of the CreationFactory class.
>>>>>>>
Thanks for your time, just looking for better solutions!
Scott
Scott,
Your solution is not guaranteed to work for various reasons
outlined
in
the article. For example, you can still return from your code apartially
initialized object. This can occur if T1 gets interrupted beforeleaving
the synchronized method createInstance() and T2 calls
getInstance().
T2
can "see" toRet/instance as non-null but partially initialized
since
T1
has not fully flushed its values.
As of 1.5, Sun fixed various issues with the memory model that
were
broken. Double Checked Locking will still break unless you usevolatile
(which was fixed in 1.5). Therefore, the following code works:
volatile Helper helper;
Helper getHelper() {
if (helper == null)
synchronized(this) {
if (helper == null)
helper = new Helper();
return helper;
but the original DCL idiom will not work. So, your options are:
1) Use DCL with volatile (above)
2) Don't use DCL but use synchronization
3) Don't use DCL, but use a static field.
#2 and #3 are outlined in my article from 2002.
Hope this helps,
Peter
"Scott Morgan" <[email protected]>
12/26/2007 04:12 PM
Please respond to
[email protected]
To
Peter Haggar/Raleigh/IBM@IBMUS
cc
Subject
[Fwd: Double Factory replacement for Double Check #2]
Hi Peter,
Thanks for the article on the out of order write problem. Whatdo
you
think of this as a solution?
TIA,
Scott
---------------------------- Original Message----------------------------
Subject: Double Factory replacement for Double Check #2
From: "Scott Morgan" <[email protected]>
Date: Wed, December 26, 2007 2:55 pm
To: [email protected]
Hi Ward,
Here is a pattern submission
Double Factory
Lazy initialization of singletons in accepted for a while usingthe
double check pattern. However it has been discovered that the
double
check pattern isn't thread safe because of the out of order write
problem. This problem occurs when Threads entering the Singleton
Factory method return with a fully constructed, but partially
initialized, Singleton object.
>>>>>>>>
Therefore: It makes sense to look for a way to initializeSingletons
in
a Lazy and Thread Safe manor. The following illustrates a fairly
simple
solution...
package foo;
public class DoubleFactory {
private static Object instance = null;
public static Object getInstance() {
Object toRet = instance;
if (toRet == null) {
instance =
CreationFactory.createInstance();
toRet = instance;
return toRet;
private DoubleFactory() {}
public class CreationFactory {
private static Object instance = null;
public static synchronized ObjectcreateInstance()
if (instance == null) {
instance = new Object();
return instance;
This gets around the out of order write problem because all
Threads
waiting on the CreationFactory's Class monitor will have a fully
constructed and initialized instance when they actually exit the
createInstance method.
>>>>>>>>
>>>>>>>>
During runtime while the Singleton instance is getting created(constructed and initialized) there may be a few Threads waiting
on
the
CreationFactory Class's objects monitor. After that period all
the
Treads
accessing
the Singleton will have unsynchronized reads to the instance,
which
will
optimize execution.
References:
http://www.ibm.com/developerworks/java/library/j-dcl.html
Copyright 2007 Adligo Inc.Scott-Morgan wrote:
Hi All,
Thanks for your comments, here are some more....
jtahlborn you state that
the only way to guarantee that a (non-final) reference assignment is visible across threads is through the use of volatile and synchronized,
From the jvm spec
http://java.sun.com/docs/books/jls/third_edition/html/memory.html
17.4.1 Shared Variables
Memory that can be shared between threads is called shared memory or heap memory.
All instance fields, static fields and array elements are stored in heap memory.
Since both the second_reference and instance fields are both static, they are shared and visible across all threads.Yes, all these things are shared across threads, however, if you keep reading, there is a notion of "correct" sharing. obviously these values may be visible, that's why double-checked locking was used for so long before people realized it was broken. it worked most of the time, except when it didn't, and that's what i'm trying to show. that the only way to correctly share state between threads is via synchronization points, the most common being volatile and synchronized (there are a couple of other less used ones which don't apply here). The articles you linked to below from ibm cover the "visibility" in great depth, this is exactly what i am referring to.
You also state that volatile is a solution, but you seem to rebut your self in stating that the overhead for volatile is almost as great as synchronization.
This article illustrates the solution, and also comments on the overhead of volatile.
http://www.ibm.com/developerworks/library/j-jtp03304/
linked from
http://www.ibm.com/developerworks/java/library/j-dcl.html
volatile is a solution, in that it is correct, and you avoid the appearance of synchronization each time. however, since the semantics of volatile were strengthened in the new memory model, using volatile will perform practically (if not exactly) the same as simply synchronizing each time. the article you link to says exactly this under the heading "Does this fix the double-checked locking problem?".
Also could you be more specific about the example at the end of the jvm memory spec page, like a section number?It's the very last thing on the page, the "discussion" under 17.9, where it mentions that changes to "this.done" made by other threads may never be visible to the current thread. -
the demand of my application is that i can not replace for loop with a while loop.because i need fixed number of iterations and as far as i know fixed iterations could be only with possible with the for loop.
your recommended second option that i could add true/false case.
this true/false case must be inside the for loop or outside the for loop?if this case is inside the for
loop, how can i send stop command from outer while
loop?
more over do you have any example for this please?
thanks"You can execute a fixed number of iterations using a while loop by comparing the iteration count to the number of iterations you want and wiring the output of that comparison (e.g. Less Than or Equal To) to the continue (or stop) terminal of your while loop. Which comparison you use depends on personal preference, where you wire the desired count and the interation count, and whether you're using the while loop as Continue if True or Stop if True.
Ben gave you step-by-step instructions in response to your previous question. Look here for Ben's response.
Ben's response looks pretty good and detailed to me. It certa
inly deserved better than a 1-star rating. -
QuickJog 1.0 - Shuttle/Jog Replacement for Premiere CS6... almost
quickJog 1.0 - "fixing what Adobe broke in CS6"
a shuttle/jog replacement for Premiere/Prelude CS6
* see below for download links and instructions *
Introduction
I'll waste no time in expressing my opinion on this one: I loved the jog control in previous versions of Premiere, and a small part of my heart died when I realised that those beloved controls couldn't be reinstated in CS6 (though an ever larger chunk died when I realised that Q and W don't work by default in Prelude... ).
JKL is great as a concept, but in practice, not very responsive - it's difficult to make precise jumps in speed quickly, and I'd hate to log footage in CS6 using the JKL keys alone.
It was whilst reading through a different thread on the forums that I had an idea. Why not just jog with the middle mouse button? REAPER uses a similar idea to great effect for scrubbing.
And so the journey began.
Installing/using quickJog
Pre-requisites
Glovepie is only available for Windows. The script, therefore, only works on Windows.
Sorry Mac users.
To use quickJog, you'll need to download the following:
GlovePie, from glovepie.org. Doesn't matter whether you grab the version with or without emotiv support, as long as it's a recent version
The quickJog script, from bit.ly/getQuickJog (unreserved thanks go to Creative Inlet Films for hosting this)
A mouse with a middle-mouse button/clickable scroll wheel
You'll also need to ensure:
The JKL keys have not been re-mapped in Premiere. This is essential, as quickJog 'presses' the JKL keys to alter the jog speed in Premiere.
Installation/usage
Is currently as simple as...
Start Glovepie
From the File menu, select Open...
Navigate to wherever you unzipped the quickJog script. Open it.
Click the Run button
Click the [ .] button at the end of the menu bar to minimise Glovepie to the system tray
To shuttle, click on the program monitor, source monitor or trim monitor, and scroll the mouse wheel. This functionality is built-into Premiere. You can hold Shift for bigger jumps.
To jog, click and hold the middle-mouse button over the source monitor, program monitor, or timeline, and move left or right to increase/decrese the jog speed (just like the old jog slider).
QuickJog tracks the position of the mouse itself, not the position of your mouse cursor, so don't worry about the cursor touching the edge of your screen.
Keep your eyes on the video, not the mouse!
To exit, right-click the glovePie icon, and select Exit.
quickJog works in Prelude too, which is pretty cool.
Links/Misc
HOW AWESOME WOULD SOME EXTRA BITS OF INFORMATION BE FOR THE WORLD? Like information on how to tweak the configuration variables??
Pretty awesome, I'd say James. Have you thought about actually writing this section, then?
Paha! Don't be crass.
Aww.I stand humbly informed!
In hindsight, I'm not surprised that the JKL keys are a popular choice amongst editors (especially for those who've moved across from other NLEs), but it does rest somewhat uncomfortably in my heart. It feels like Adobe have replaced the pedals and gearstick in my car with a keyboard: not great for those moments when a child runs into the road.
The Shuttle Pro (and Bella to my knowledge?) controllers emulate left/right arrow keypresses to do their work, making the playback 'glitchy' during shuttle operations - I don't like that. I didn't particularly like the feel of the Shuttle Pro when I tried it either. I do like controllers like this (I have one), but have been working for some time on interfacing between the Sony 9-pin protocol and Premiere.
As such, my intermediate preference has been to use a graphics tablet (with a keyboard) for NLE work - hence why having the jog/shuttle controls on screen was so darn useful! Now that I have quickJog mapped to the stylus eraser, edits are much faster.
Quick aside: Huge commendations on just how much can be mapped to keyboard shortcuts in Premiere, huzzah! -
New Macbook a good replacement for 12" Powerbook?
I think, besides the inch in display difference, that the new macbook WOULD HAVE made a GREAT GREAT GREAT replacement for users loving or wanting the portability, yet pro versatility of the old 12" Powerbooks. I think however that Apple has missed the mark in one BIG BIG WAY! Firewire. People who wanted something like the 12" powerbook wanted the power of the Macbook Pro in a smaller package. Apple hit the nail on the head with incorporating the same graphics performance, by using aluminum, by making it lighter, and by putting in the illuminated keyboard (only in the 2.4 model though). But on the last detail, they missed it. Firewire. there is no workaround. period. Why preload the systems with iMovie when you can't import video from MOST modern digital camcorders? WITHOUT EVEN introducing a new port with adapters (like they did with the Display Port). I think I would've sold my old macbook pro and had instantly purchased the new macbook if Apple had just included that one VITAL port. I would even prefer them putting it in the place of one of the two USB ports. But without being able to import video from my NEW minidv, there is just no way i could buy that macbook and call myself a proud mac owner. What kind of digital hub would that be? Isn't your slogan "works right out of the box."...? what do you guys think about the new macbook being a 12" powerbook replacement??
I have the same situation. I wanted to upgrade from my 12" Powerbook and would move up to the 13" screen of the new MacBook (15" is much too big for my needs). Another family member has the 15" Powerbook and has always liked my smaller size. I was ready to order 2 of the 13" MacBooks and was then stunned to see that Firewire was missing. I have a Sony DV camcorder for movies. It appears Apple expects me to use my old Powerbooks to input the video into iMovie and then transfer it over to my new MacBook. This is not the cutting edge Apple Computer Company that I have been a customer of for 25 years.
If Apple wants to add firewire to the new MacBooks, develop a USB / Ethernet to firewire adapter, or add a 13" MacBook Pro (w/ firewire) to the line-up, they will have a customer. Otherwise, I will hold onto my old Powerbooks until this is corrected. -
APEX Listener as a replacement for modplsql ?
Will APEX Listener ever be, or is it able to be now, a replacement for modplsql driven applications that are not APEX. It seems that it already takes care of everything needed to be a full scale modplsql replacement... In all honesty looking to see if it is possible to reduce the future licensing load on some of my clients if they wanted to build more redundancy into their front-end web applications. They wouldn't be reducing what they pay, as they are still in for the Forms installs in app server, but they are inhibited on their redundancy growth outward since adding new licenses to cover these new servers would be cost prohibitive. This is mainly a third-party product (SGHE's Self-Service Banner) that is driven off of modplsql, so rewrite isn't an option.
Thanks for your input,
-RichardAs of the last EA version, it depends on which modplsql features your application uses. The main modplsql features that are not yet supported are:
Basic database authentication - The listener must be configured with a single username and password and cannot dynamically change the database connection at run time.
Multiple DADS - Each listener is configured for one and only one database connection. However, there is a way to install multiple copies of the listener, and configure each for a different database connection.
Dynamic parameter passing - There must be a one to one relationship between fields on an HTML form (or query string variables in the URL) and the non-defaulted parameters of the called procedure. Name and Value arrays, with the "!" before the procedure name in the URL are not supported.
CGI environment variables in the DAD.
Oracle MAY support some or all of these features in the production version, or in some future version. We can probably influence this by telling Oracle what we want - but no guarantees. Kris Rice tells me that the APEX Listener was written to be extendable, so once Oracle gives us some documentation of how to extend it, some enterprising programmer may add some of these features as an extension. -
Replacement for dvi to vga adapter for late 2008 17"Macbook pro
Hello,
I have a 17" inch late 2008 mack pro. The apple dvi to vga adapter cable is not working anymore. I can seem to find a replacement for it. I have tried the generic dvi to vga adapter (image attached). This does not work. Please adviseHello mshameel,
It may help to reset your system's SMC and NVRAM.
Intel-based Macs: Resetting the System Management Controller (SMC)
http://support.apple.com/kb/HT3964
About NVRAM and PRAM
http://support.apple.com/kb/HT1379
Cheers,
Allen
Maybe you are looking for
-
I wish to sell my 2008 MacBook Pro. Have erased hard disk and when I went to fresh instal Mavericks OSX 10.6 (it gives me no other choice in the disk utility program) It says in the Apple Store, it is unavailable. But because this is done from disk u
-
Question regarding generics and collections
Hi, I am stuying the Sierra and Bates book for SCJP. One particular answer to a question in it is puzzling me at the moment: Given a method as public static <E extends Number> List<E> process(List<E> nums) A programmer wants to use this method like t
-
Podcast - Download when Sync'ing iTunes say no longer exist
I decided to try and download Podcasts after getting a wee bit bored of them in the past. I went to the iTunes Store podcast section Selected Chris Moyles (non-enhanced) Russel Brand They both downloaded fine and are sat on my iTunes library. However
-
I have a solution for the Administrator Error
Hi all, I have also been having serious problems with the message "An error occurred while installing Adobe AIR. Installation may not be allowed by your administrator. Please contact your administrator". I have found a SOLUTION that has worked for
-
SD card import faulty - Camera Connection Kit
I am travelling around and the camera connection kit has been working well for importing pics from my SD cards. However one day the import warned me I was importing 1gb of pics, but only had 0.7gb free on the iPad. It asked me whether to import until