You are viewing a plain text version of this content. The canonical link for it is here.
Posted to ojb-dev@db.apache.org by ar...@apache.org on 2004/06/12 16:38:59 UTC
cvs commit: db-ojb/src/java/org/apache/ojb/broker/metadata MetadataManager.java
arminw 2004/06/12 07:38:59
Modified: src/java/org/apache/ojb/broker/metadata MetadataManager.java
Log:
minor change, make sure that only one instance was created
Revision Changes Path
1.18 +10 -16 db-ojb/src/java/org/apache/ojb/broker/metadata/MetadataManager.java
Index: MetadataManager.java
===================================================================
RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/metadata/MetadataManager.java,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -r1.17 -r1.18
--- MetadataManager.java 27 May 2004 21:04:41 -0000 1.17
+++ MetadataManager.java 12 Jun 2004 14:38:59 -0000 1.18
@@ -15,19 +15,19 @@
* limitations under the License.
*/
-import org.apache.commons.lang.SerializationUtils;
-import org.apache.ojb.broker.core.PersistenceBrokerConfiguration;
-import org.apache.ojb.broker.util.configuration.impl.OjbConfigurator;
-import org.apache.ojb.broker.util.logging.Logger;
-import org.apache.ojb.broker.util.logging.LoggerFactory;
-import org.apache.ojb.broker.PBKey;
-
import java.io.FileNotFoundException;
import java.io.InputStream;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.List;
+import org.apache.commons.lang.SerializationUtils;
+import org.apache.ojb.broker.PBKey;
+import org.apache.ojb.broker.core.PersistenceBrokerConfiguration;
+import org.apache.ojb.broker.util.configuration.impl.OjbConfigurator;
+import org.apache.ojb.broker.util.logging.Logger;
+import org.apache.ojb.broker.util.logging.LoggerFactory;
+
/**
* Central class for metadata operations/manipulations - manages OJB's
* metadata objects, in particular:
@@ -123,9 +123,8 @@
private static Logger log = LoggerFactory.getLogger(MetadataManager.class);
private static final String MSG_STR = "* Can't find DescriptorRepository for current thread, use default one *";
-
private static ThreadLocal threadedRepository = new ThreadLocal();
- private static MetadataManager singleton = null;
+ private static MetadataManager singleton = new MetadataManager();
private Hashtable metadataProfiles;
private DescriptorRepository globalRepository;
@@ -157,7 +156,7 @@
}
catch (Exception ex)
{
- throw new MetadataException("Could not read repository file" + repository, ex);
+ throw new MetadataException("Can't read repository file '" + repository + "'", ex);
}
this.defaultPBKey = buildDefaultKey();
}
@@ -167,11 +166,6 @@
*/
public static MetadataManager getInstance()
{
- // lazy initialization
- if (singleton == null)
- {
- singleton = new MetadataManager();
- }
return singleton;
}
---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-dev-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-dev-help@db.apache.org
Re: cvs commit: db-ojb/src/java/org/apache/ojb/broker/metadata MetadataManager.java
Posted by Armin Waibel <ar...@apache.org>.
Thomas Dudziak wrote:
> On Sat, 12 Jun 2004, Armin Waibel wrote:
>
>
>>Synchronization is the crucial point!
>>I don't want to make the method synchronized to avoid performance
>>decrease. But if you have problems with logging initializing it's ok to
>>use the old version with synchronized method.
>
>
> What do you think, is it really crucial in this case ? I don't know, is
> this method called often ?
>
Not too often. I rolled back and make method synchronized.
Armin
> Tom
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: ojb-dev-unsubscribe@db.apache.org
> For additional commands, e-mail: ojb-dev-help@db.apache.org
>
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-dev-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-dev-help@db.apache.org
Re: cvs commit: db-ojb/src/java/org/apache/ojb/broker/metadata
MetadataManager.java
Posted by Thomas Dudziak <to...@first.fhg.de>.
On Sat, 12 Jun 2004, Armin Waibel wrote:
> Synchronization is the crucial point!
> I don't want to make the method synchronized to avoid performance
> decrease. But if you have problems with logging initializing it's ok to
> use the old version with synchronized method.
What do you think, is it really crucial in this case ? I don't know, is
this method called often ?
Tom
---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-dev-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-dev-help@db.apache.org
Re: cvs commit: db-ojb/src/java/org/apache/ojb/broker/metadata MetadataManager.java
Posted by Armin Waibel <ar...@apache.org>.
Thomas Dudziak wrote:
> On Sat, 12 Jun 2004, Armin Waibel wrote:
>
>
>>Does this cause problems?
>>We have to make sure that it is guaranteed that only one instance of
>>MetadataManager was created. With the old version it is not guaranteed
>>(the old singleton problem ;-))
>
>
> Well yes, if you want to initialize logging and OJB at runtime (which I'm
> working on at the moment). Any why was this not guaranteed in the old
> version (aside from the fact that there was no synchronized guard in the
> method) ?
Synchronization is the crucial point!
I don't want to make the method synchronized to avoid performance
decrease. But if you have problems with logging initializing it's ok to
use the old version with synchronized method.
regards,
Armin
How about:
>
> public syncronized static MetadataManager getInstance()
> {
> // lazy initialization
> if (singleton == null)
> {
> singleton = new MetadataManager();
> }
> return singleton;
> }
>
> Shouldn't that work ?
>
> Tom
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: ojb-dev-unsubscribe@db.apache.org
> For additional commands, e-mail: ojb-dev-help@db.apache.org
>
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-dev-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-dev-help@db.apache.org
Re: cvs commit: db-ojb/src/java/org/apache/ojb/broker/metadata
MetadataManager.java
Posted by Thomas Dudziak <to...@first.fhg.de>.
On Sat, 12 Jun 2004, Armin Waibel wrote:
> Does this cause problems?
> We have to make sure that it is guaranteed that only one instance of
> MetadataManager was created. With the old version it is not guaranteed
> (the old singleton problem ;-))
Well yes, if you want to initialize logging and OJB at runtime (which I'm
working on at the moment). Any why was this not guaranteed in the old
version (aside from the fact that there was no synchronized guard in the
method) ? How about:
public syncronized static MetadataManager getInstance()
{
// lazy initialization
if (singleton == null)
{
singleton = new MetadataManager();
}
return singleton;
}
Shouldn't that work ?
Tom
---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-dev-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-dev-help@db.apache.org
Re: cvs commit: db-ojb/src/java/org/apache/ojb/broker/metadata MetadataManager.java
Posted by Armin Waibel <ar...@apache.org>.
Thomas Dudziak wrote:
> Armin, that's the same functionality (there was only one instance created
> before) with one major difference: now the MetadataManager is instantiated
> as soon as the class is loaded where before it was instantiated only when
> first used. Could you perhaps undo your change because the effect is that
> this way OJB is initialized a lot earlier than necessary ?
>
Does this cause problems?
We have to make sure that it is guaranteed that only one instance of
MetadataManager was created. With the old version it is not guaranteed
(the old singleton problem ;-))
regards,
Armin
> Tom
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: ojb-dev-unsubscribe@db.apache.org
> For additional commands, e-mail: ojb-dev-help@db.apache.org
>
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-dev-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-dev-help@db.apache.org
Re: cvs commit: db-ojb/src/java/org/apache/ojb/broker/metadata
MetadataManager.java
Posted by Thomas Dudziak <to...@first.fhg.de>.
Armin, that's the same functionality (there was only one instance created
before) with one major difference: now the MetadataManager is instantiated
as soon as the class is loaded where before it was instantiated only when
first used. Could you perhaps undo your change because the effect is that
this way OJB is initialized a lot earlier than necessary ?
Tom
---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-dev-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-dev-help@db.apache.org