From 6efe68782517c8a6a4977bc68caeb8929d2b175d Mon Sep 17 00:00:00 2001 From: "nor..67" Date: Wed, 30 Jan 2013 12:38:06 +0000 Subject: [PATCH] SDK: - improve AssetData mutex use git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@10241 75d07b2b-3a1a-0410-a2c5-0572b91ccdca --- .../com/jme3/gde/core/assets/AssetData.java | 55 +++++++++---------- 1 file changed, 26 insertions(+), 29 deletions(-) diff --git a/sdk/jme3-core/src/com/jme3/gde/core/assets/AssetData.java b/sdk/jme3-core/src/com/jme3/gde/core/assets/AssetData.java index eda0b594d..beb2c7cf5 100644 --- a/sdk/jme3-core/src/com/jme3/gde/core/assets/AssetData.java +++ b/sdk/jme3-core/src/com/jme3/gde/core/assets/AssetData.java @@ -126,32 +126,33 @@ public class AssetData { } public synchronized String getProperty(final String key) { + readProperties(); return propsMutex.readAccess(new Action() { public String run() { - readProperties(); return props.getProperty(key); } }); } public synchronized String getProperty(final String key, final String defaultValue) { + readProperties(); return propsMutex.readAccess(new Action() { public String run() { - readProperties(); return props.getProperty(key, defaultValue); } }); } public synchronized String setProperty(final String key, final String value) { - return propsMutex.writeAccess(new Action() { + readProperties(); + String ret = propsMutex.writeAccess(new Action() { public String run() { String ret = (String) props.setProperty(key, value); - readProperties(); - writeProperties(); return ret; } }); + writeProperties(); + return ret; } @Deprecated @@ -163,7 +164,7 @@ public class AssetData { } private void readProperties() { - propsMutex.readAccess(new Runnable() { + propsMutex.writeAccess(new Runnable() { public void run() { final FileObject myFile = FileUtil.findBrother(file.getPrimaryFile(), extension); if (myFile == null) { @@ -171,30 +172,26 @@ public class AssetData { } final Date lastMod = myFile.lastModified(); if (!lastMod.equals(lastLoaded)) { - propsMutex.writeAccess(new Runnable() { - public void run() { - props.clear(); - lastLoaded = lastMod; - InputStream in = null; - try { - in = new BufferedInputStream(myFile.getInputStream()); - try { - props.load(in); - } catch (IOException ex) { - Exceptions.printStackTrace(ex); - } - } catch (FileNotFoundException ex) { - Exceptions.printStackTrace(ex); - } finally { - try { - in.close(); - } catch (IOException ex) { - Exceptions.printStackTrace(ex); - } - } - logger.log(Level.INFO, "Read AssetData properties for {0}", file); + props.clear(); + lastLoaded = lastMod; + InputStream in = null; + try { + in = new BufferedInputStream(myFile.getInputStream()); + try { + props.load(in); + } catch (IOException ex) { + Exceptions.printStackTrace(ex); } - }); + } catch (FileNotFoundException ex) { + Exceptions.printStackTrace(ex); + } finally { + try { + in.close(); + } catch (IOException ex) { + Exceptions.printStackTrace(ex); + } + } + logger.log(Level.INFO, "Read AssetData properties for {0}", file); } } });