|
From: <to...@us...> - 2007-02-13 00:57:14
|
Revision: 57
http://techne-dev.svn.sourceforge.net/techne-dev/?rev=57&view=rev
Author: tonit
Date: 2007-02-12 16:57:09 -0800 (Mon, 12 Feb 2007)
Log Message:
-----------
added double check locking in next() to make this boring sample more educative ;-)
Modified Paths:
--------------
sandbox/tonit/techne.audio/src/techne/audio/samplemusic/SampleMusicSource.java
Modified: sandbox/tonit/techne.audio/src/techne/audio/samplemusic/SampleMusicSource.java
===================================================================
--- sandbox/tonit/techne.audio/src/techne/audio/samplemusic/SampleMusicSource.java 2007-02-13 00:11:08 UTC (rev 56)
+++ sandbox/tonit/techne.audio/src/techne/audio/samplemusic/SampleMusicSource.java 2007-02-13 00:57:09 UTC (rev 57)
@@ -31,15 +31,20 @@
}
public InputStream next() {
- synchronized (this) {
- if (count == 0) {
- count++;
- try {
- System.out.println("MusicSource: giving " + url.toExternalForm());
- return url.openConnection().getInputStream();
- } catch (IOException e) {
- e.printStackTrace();
- throw new RuntimeException(e);
+ // double check locking to make this boring sample more educative ;-)
+ if (hasNext()) {
+ synchronized (this) {
+ if (hasNext()) {
+ count++;
+ try {
+ // you get always the same for this example either..
+ System.out.println("MusicSource: giving "
+ + url.toExternalForm());
+ return url.openConnection().getInputStream();
+ } catch (IOException e) {
+ e.printStackTrace();
+ throw new RuntimeException(e);
+ }
}
}
}
@@ -62,7 +67,8 @@
// Declarative Services methods..
protected void activate(ComponentContext context) {
System.out.println("Started sample MusicSource for techne.audio");
- url = context.getBundleContext().getBundle().getResource("TotallyFreeSong.mp3");
+ url = context.getBundleContext().getBundle().getResource(
+ "TotallyFreeSong.mp3");
}
public void deactivate(ComponentContext context) throws Exception {
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|