[appengine-java] Re: Multiple PersistenceManagerFactory with Singleton?

2011-08-10 Thread dimi
Thanks. I should have know that things they learn you at school, don't work 
in real life :-)

-- 
You received this message because you are subscribed to the Google Groups 
"Google App Engine for Java" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/google-appengine-java/-/kOwEJSNnKRAJ.
To post to this group, send email to google-appengine-java@googlegroups.com.
To unsubscribe from this group, send email to 
google-appengine-java+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-appengine-java?hl=en.



[appengine-java] Re: Multiple PersistenceManagerFactory with Singleton?

2011-08-10 Thread gk
Dimitry,  see http://en.wikipedia.org/wiki/Singleton_pattern for the
Singleton - it explains why your last code snippet does not always
work as it is not thread safe and can cause multiple instance to be
created.

On Aug 10, 11:33 am, dimi  wrote:
> I was afraid about that..
>
> I'm using Objectify for my future projects, so if it happens again.. I'll
> blame someone else :)
>
> But it still doesn't explain why only the queries on kind A went wrong...
> (unless there were more instances)

-- 
You received this message because you are subscribed to the Google Groups 
"Google App Engine for Java" group.
To post to this group, send email to google-appengine-java@googlegroups.com.
To unsubscribe from this group, send email to 
google-appengine-java+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-appengine-java?hl=en.



[appengine-java] Re: Multiple PersistenceManagerFactory with Singleton?

2011-08-10 Thread gk
Simon,

this is equivalent "public static final void  a(){}" and "public
static void  a(){}" - following of course not "public static final int
b" and "public static int b".

On Aug 9, 5:57 pm, Simon Knott  wrote:
> Whilst I don't know what could cause this error, what makes you believe that
> "static" and "static final" are equivalent?  Static variables are in no way
> implicitly final.

-- 
You received this message because you are subscribed to the Google Groups 
"Google App Engine for Java" group.
To post to this group, send email to google-appengine-java@googlegroups.com.
To unsubscribe from this group, send email to 
google-appengine-java+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-appengine-java?hl=en.



[appengine-java] Re: Multiple PersistenceManagerFactory with Singleton?

2011-08-10 Thread dimi
I was afraid about that..

I'm using Objectify for my future projects, so if it happens again.. I'll 
blame someone else :)

But it still doesn't explain why only the queries on kind A went wrong... 
(unless there were more instances)

-- 
You received this message because you are subscribed to the Google Groups 
"Google App Engine for Java" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/google-appengine-java/-/CcaS_5PjAmQJ.
To post to this group, send email to google-appengine-java@googlegroups.com.
To unsubscribe from this group, send email to 
google-appengine-java+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-appengine-java?hl=en.



[appengine-java] Re: Multiple PersistenceManagerFactory with Singleton?

2011-08-10 Thread Simon Knott
If that was your original code, that could definitely cause the problem - 
two threads can both hit that method at the same time and create a new 
PersistenceManager.

-- 
You received this message because you are subscribed to the Google Groups 
"Google App Engine for Java" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/google-appengine-java/-/XAdp937hFfkJ.
To post to this group, send email to google-appengine-java@googlegroups.com.
To unsubscribe from this group, send email to 
google-appengine-java+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-appengine-java?hl=en.



[appengine-java] Re: Multiple PersistenceManagerFactory with Singleton?

2011-08-09 Thread dimi
gk and Simon,

Thanks for you reply. 

After reading my own post again, I noticed I copied the wrong PMF code. I'm 
using this example (the mix up happened when I changed my code to the code 
above because I though the "pmfInstance == null"-check could be the problem 
:D)

import javax.jdo.JDOHelper;
import javax.jdo.PersistenceManagerFactory;

public class PMF
{
private static PersistenceManagerFactory pmfInstance = null;
private PMF() {}
public static PersistenceManagerFactory getInstance()
{
if (pmfInstance == null)
{
pmfInstance = 
JDOHelper.getPersistenceManagerFactory("transactions-optional");
}
return pmfInstance;
}
}

-- 
You received this message because you are subscribed to the Google Groups 
"Google App Engine for Java" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/google-appengine-java/-/bmaMmcCqMHoJ.
To post to this group, send email to google-appengine-java@googlegroups.com.
To unsubscribe from this group, send email to 
google-appengine-java+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-appengine-java?hl=en.



[appengine-java] Re: Multiple PersistenceManagerFactory with Singleton?

2011-08-09 Thread Simon Knott
Whilst I don't know what could cause this error, what makes you believe that 
"static" and "static final" are equivalent?  Static variables are in no way 
implicitly final.

-- 
You received this message because you are subscribed to the Google Groups 
"Google App Engine for Java" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/google-appengine-java/-/97oKfhMuBg0J.
To post to this group, send email to google-appengine-java@googlegroups.com.
To unsubscribe from this group, send email to 
google-appengine-java+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-appengine-java?hl=en.



[appengine-java] Re: Multiple PersistenceManagerFactory with Singleton?

2011-08-09 Thread gk
Dimitry,

that's a nice mystery...

"final" on PMF doesn't seem to make a difference here. "static"
members are implicitly "final" too, by the way ("static" and "static
final" is equivalent). Class type inititialization (and thus static
field initialization) is implicitly synchronized, so no worry there
either (see http://en.wikipedia.org/wiki/Singleton_pattern).

With lazy initialization you could at least intercept and log a stack
trace... maybe that would give you a hint.


On Aug 7, 11:49 pm, dimi  wrote:
> Hello guys,
>
> I've got an app running for 1.3 months now, without any problem...
>
> Until today, just before 3PM (GMT+2) my app stopped serving all queries from
> kind A.
> All the other kinds (B, C, D,...) still worked.
>
> When I looked it up in the logs, I found this error multiple times when
> querying kind A.
>
> javax.jdo.JDOFatalUserException: Application code attempted to create a
> PersistenceManagerFactory named transactions-optional, but one with this
> name already exists!  Instances of PersistenceManagerFactory are extremely
> slow to create and it is usually not necessary to create one with a given
> name more than once.  Instead, create a singleton and share it throughout
> your code.  If you really do need to create a duplicate
> PersistenceManagerFactory (such as for a unittest suite), set the
> appengine.orm.disable.duplicate.pmf.exception system property to avoid this
> error.
>
> The problem is obvious you say?
> It would be, but I already use a Singleton. (And I searched my source
> files.. I never create more than one instance!)
>
> I'm using this code (it comes out of the JDO Google documentation):
>
> import javax.jdo.JDOHelper;
> import javax.jdo.PersistenceManagerFactory;
>
> public final class PMF {
>     private static final PersistenceManagerFactory pmfInstance =
>         JDOHelper.getPersistenceManagerFactory("transactions-optional");
>
>     private PMF() {}
>
>     public static PersistenceManagerFactory get() {
>         return pmfInstance;
>     }
>
> }
>
> I did define my app as true so could I be a lucky
> lottery winner? Meaning that the pmfInstance was set twice on exactly the
> same moment? Should I put it in a synchronised block? Or should I use this
> code?
>
> public class PMF
> {
> private static final PersistenceManagerFactory pmfInstance =
> JDOHelper.getPersistenceManagerFactory("transactions-optional");
>
>     private PMF() {}
>
>     public static PersistenceManagerFactory getInstance()
>     {
>         return pmfInstance;
>     }
>
> }
>
> But, it does not explain why I only had problems while executing queries of
> kind A.. The other queries over other kinds still worked.
>
> Unfortunately, I discovered the problem 4 hours later and the problem was
> still accurate. Only disabling the app killed all running java instances and
> solved my problem.
>
> Any ideas what could have caused this?
>
> Thnx!
>
> Dimitri

-- 
You received this message because you are subscribed to the Google Groups 
"Google App Engine for Java" group.
To post to this group, send email to google-appengine-java@googlegroups.com.
To unsubscribe from this group, send email to 
google-appengine-java+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-appengine-java?hl=en.