<?xml version="1.0" encoding="UTF-8"?>
	<rss version="2.0"
		xmlns:content="http://purl.org/rss/1.0/modules/content/"
		xmlns:wfw="http://wellformedweb.org/CommentAPI/"
		xmlns:dc="http://purl.org/dc/elements/1.1/"
		xmlns:atom="http://www.w3.org/2005/Atom"

			>

	<channel>
		<title>Cycling 74  &#187;  Topic: Singleton issues.</title>
		<atom:link href="http://cycling74.com/forums/topic/singleton-issues/feed" rel="self" type="application/rss+xml" />
		<link>http://cycling74.com/forums/topic/singleton-issues/feed</link>
		<description></description>
		<pubDate>Tue, 18 Jun 2013 23:30:27 +0000</pubDate>
		<generator>http://bbpress.org/?v=2.2.4</generator>
		<language></language>

		
														
					
				<item>
					<guid>http://cycling74.com/forums/topic/singleton-issues/#post-31744</guid>
					<title><![CDATA[Singleton issues.]]></title>
					<link>http://cycling74.com/forums/topic/singleton-issues/#post-31744</link>
					<pubDate>Fri, 04 May 2007 02:44:37 +0000</pubDate>
					<dc:creator>Matthew Aidekman</dc:creator>

					<description>
						<![CDATA[
						<p>Ok I&#8217;m going to try and explain this as succinctly as possible.  it may be a brain teaser.   I&#8217;m a beginner javamaxer. In fact I just learned what a singleton was.   What I&#8217;m doing in reality is editing the Java JitterGui. but I&#8217;ve mangled it pretty fearsome.  I&#8217;m thinking what I need is an ?interface? of some sort.  </p>
<p>this link might help.  I&#8217;m thinking maybe its &#8220;different classloaders&#8221; ???</p>
<p><a href="http://java.sun.com/developer/technicalArticles/Programming/singletons/" rel="nofollow">http://java.sun.com/developer/technicalArticles/Programming/singletons/</a></p>
<p>
6 classes<br />
GlobalTest_Singleton     has a is exactly what it says<br />
GlobalTest_Element is a prototype for an element which is instantiated by an &#8220;extends maxobject&#8221;<br />
GlobalTest_Sub1Element : type of element to be instantiated inside an &#8220;extends maxobject&#8221;<br />
GlobalTest_Sub2Element : type of element to be instantiated inside an &#8220;extends maxobject&#8221;<br />
GlobalTest_Sub1: an &#8220;extends maxobject&#8221; which instantiates Sub1Element<br />
GlobalTest_Sub2: an &#8220;extends maxobject&#8221; which instantiates Sub2Element</p>
<p>
what I need is for getSingleton() to work in  Sub1Element, Sub2Element, Sub1, and Sub2 so that they all reference the same instance of singleton.</p>
<p>//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////<br />
import com.cycling74.max.*;</p>
<p>public class GlobalTest_Singleton<br />
{<br />
 	private static GlobalTest_Singleton theonlyone = new GlobalTest_Singleton();</p>
<p>	private GlobalTest_Singleton()<br />
	{	}</p>
<p>	public static GlobalTest_Singleton get_Singleton() {<br />
      return theonlyone;<br />
	}<br />
}<br />
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////<br />
import com.cycling74.max.*;</p>
<p>public class GlobalTest_Element <br />
{</p>
<p>	public  static GlobalTest_Singleton gui = GlobalTest_Singleton.get_Singleton();</p>
<p>	public GlobalTest_Element()<br />
	{<br />
	}<br />
}<br />
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////<br />
import com.cycling74.max.*;</p>
<p>public class GlobalTest_Sub1Element extends GlobalTest_Element<br />
{</p>
<p>	public  GlobalTest_Sub1Element()<br />
	{<br />
	MaxObject.post(&#8220;Sub1Element constructor: &#8220;+gui);<br />
	}</p>
<p>}<br />
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////<br />
import com.cycling74.max.*;</p>
<p>public class GlobalTest_Sub2Element extends GlobalTest_Element<br />
{<br />
	public  GlobalTest_Sub2Element()<br />
	{<br />
	MaxObject.post(&#8220;Sub1Element constructor: &#8220;+gui);<br />
	}<br />
}<br />
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////<br />
import com.cycling74.max.*;</p>
<p>public class GlobalTest_Sub1 extends MaxObject<br />
{<br />
	private  GlobalTest_Sub1Element s=null;</p>
<p>	private  GlobalTest_Singleton gui2 = GlobalTest_Singleton.get_Singleton();</p>
<p>	public GlobalTest_Sub1(Atom[] args)<br />
	{<br />
		declareInlets(new int[]{DataTypes.ALL});<br />
		declareOutlets(new int[]{DataTypes.ALL});</p>
<p>		s = new GlobalTest_Sub1Element();<br />
		post(&#8220;GlobalTest_Sub1 gui= &#8220;+s.gui);<br />
		post(&#8220;GlobalTest_Sub1 gui2= &#8220;+gui2);</p>
<p>	} <br />
}<br />
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////<br />
import com.cycling74.max.*;</p>
<p>public class GlobalTest_Sub2 extends MaxObject<br />
{<br />
	private  GlobalTest_Singleton gui2 = GlobalTest_Singleton.get_Singleton();</p>
<p>	private  GlobalTest_Sub2Element s=null;</p>
<p>	public GlobalTest_Sub2(Atom[] args)<br />
	{<br />
		declareInlets(new int[]{DataTypes.ALL});<br />
		declareOutlets(new int[]{DataTypes.ALL});</p>
<p>		s = new GlobalTest_Sub2Element();<br />
		post(&#8220;GlobalTest_Sub2 gui= &#8220;+s.gui);<br />
		post(&#8220;GlobalTest_Sub2 gui2= &#8220;+gui2);<br />
	}    <br />
}</p>
						]]>
					</description>

					
					
				</item>

			
				<item>
					<guid>http://cycling74.com/forums/topic/singleton-issues/#post-103525</guid>
					<title><![CDATA[Re: Singleton issues.]]></title>
					<link>http://cycling74.com/forums/topic/singleton-issues/#post-103525</link>
					<pubDate>Fri, 04 May 2007 05:41:11 +0000</pubDate>
					<dc:creator>Ignotus</dc:creator>

					<description>
						<![CDATA[
						<p>Matt,</p>
<p>>From a glance at your code, it would seem to be a correct<br />
implementation of one of the ways of implementing a Singleton. Deos it<br />
work when you test it?</p>
<p>The other approach is to declare the single instance final:</p>
<p>public class Benedict {<br />
    public static final Benedict INSTANCE = new Benedict();</p>
<p>    private Benedict() {<br />
        &#8230;<br />
    }</p>
<p>    &#8230;  // etc.<br />
}</p>
<p>The static factory method you use is more flexible, though perhaps<br />
minimally less efficient (or so say the books I&#8217;ve been reading).</p>
<p>I guess the real question is what you want to use it<br />
for&#8230;constructing a gui sounds a little odd, but I don&#8217;t know the<br />
circumstances. A great book for getting started with design patterns<br />
(among them the singleton) is O&#8217;Reilly&#8217;s Head First Design Patterns.<br />
Also has an innovative approach to design itself.</p>
<p>&#8211; Paul</p>
<p>On 5/3/07, Matthew Aidekman
<puuukeey @comcast.net> wrote:<br />
><br />
> Ok I&#8217;m going to try and explain this as succinctly as possible.  it may be a brain teaser.   I&#8217;m a beginner javamaxer. In fact I just learned what a singleton was.   What I&#8217;m doing in reality is editing the Java JitterGui. but I&#8217;ve mangled it pretty fearsome.  I&#8217;m thinking what I need is an ?interface? of some sort.<br />
><br />
> this link might help.  I&#8217;m thinking maybe its &#8220;different classloaders&#8221; ???<br />
> <a href="http://java.sun.com/developer/technicalArticles/Programming/singletons/" rel="nofollow">http://java.sun.com/developer/technicalArticles/Programming/singletons/</a><br />
><br />
><br />
> 6 classes<br />
> GlobalTest_Singleton     has a is exactly what it says<br />
> GlobalTest_Element is a prototype for an element which is instantiated by an &#8220;extends maxobject&#8221;<br />
> GlobalTest_Sub1Element : type of element to be instantiated inside an &#8220;extends maxobject&#8221;<br />
> GlobalTest_Sub2Element : type of element to be instantiated inside an &#8220;extends maxobject&#8221;<br />
> GlobalTest_Sub1: an &#8220;extends maxobject&#8221; which instantiates Sub1Element<br />
> GlobalTest_Sub2: an &#8220;extends maxobject&#8221; which instantiates Sub2Element<br />
><br />
><br />
> what I need is for getSingleton() to work in  Sub1Element, Sub2Element, Sub1, and Sub2 so that they all reference the same instance of singleton.<br />
><br />
><br />
><br />
> //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////<br />
> import com.cycling74.max.*;<br />
><br />
> public class GlobalTest_Singleton<br />
> {<br />
>         private static GlobalTest_Singleton theonlyone = new GlobalTest_Singleton();<br />
><br />
>         private GlobalTest_Singleton()<br />
>         {       }<br />
><br />
>         public static GlobalTest_Singleton get_Singleton() {<br />
>       return theonlyone;<br />
>         }<br />
> }<br />
> //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////<br />
> import com.cycling74.max.*;<br />
><br />
> public class GlobalTest_Element<br />
> {<br />
><br />
>         public  static GlobalTest_Singleton gui = GlobalTest_Singleton.get_Singleton();<br />
><br />
>         public GlobalTest_Element()<br />
>         {<br />
>         }<br />
> }<br />
> //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////<br />
> import com.cycling74.max.*;<br />
><br />
> public class GlobalTest_Sub1Element extends GlobalTest_Element<br />
> {<br />
><br />
>         public  GlobalTest_Sub1Element()<br />
>         {<br />
>         MaxObject.post(&#8220;Sub1Element constructor: &#8220;+gui);<br />
>         }<br />
><br />
> }<br />
> //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////<br />
> import com.cycling74.max.*;<br />
><br />
> public class GlobalTest_Sub2Element extends GlobalTest_Element<br />
> {<br />
>         public  GlobalTest_Sub2Element()<br />
>         {<br />
>         MaxObject.post(&#8220;Sub1Element constructor: &#8220;+gui);<br />
>         }<br />
> }<br />
> //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////<br />
> import com.cycling74.max.*;<br />
><br />
> public class GlobalTest_Sub1 extends MaxObject<br />
> {<br />
>         private  GlobalTest_Sub1Element s=null;<br />
><br />
>         private  GlobalTest_Singleton gui2 = GlobalTest_Singleton.get_Singleton();<br />
><br />
>         public GlobalTest_Sub1(Atom[] args)<br />
>         {<br />
>                 declareInlets(new int[]{DataTypes.ALL});<br />
>                 declareOutlets(new int[]{DataTypes.ALL});<br />
><br />
>                 s = new GlobalTest_Sub1Element();<br />
>                 post(&#8220;GlobalTest_Sub1 gui= &#8220;+s.gui);<br />
>                 post(&#8220;GlobalTest_Sub1 gui2= &#8220;+gui2);<br />
><br />
>         }<br />
> }<br />
> //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////<br />
> import com.cycling74.max.*;<br />
><br />
> public class GlobalTest_Sub2 extends MaxObject<br />
> {<br />
>         private  GlobalTest_Singleton gui2 = GlobalTest_Singleton.get_Singleton();<br />
><br />
>         private  GlobalTest_Sub2Element s=null;<br />
><br />
>         public GlobalTest_Sub2(Atom[] args)<br />
>         {<br />
>                 declareInlets(new int[]{DataTypes.ALL});<br />
>                 declareOutlets(new int[]{DataTypes.ALL});<br />
><br />
>                 s = new GlobalTest_Sub2Element();<br />
>                 post(&#8220;GlobalTest_Sub2 gui= &#8220;+s.gui);<br />
>                 post(&#8220;GlobalTest_Sub2 gui2= &#8220;+gui2);<br />
>         }<br />
> }<br />
><br />
></puuukeey></p>
<p>&#8211; <br />
&#8212;&#8211;   |(*,+,#,=)(#,=,*,+)(=,#,+,*)(+,*,=,#)|   &#8212;&#8211;</p>
						]]>
					</description>

					
					
				</item>

			
				<item>
					<guid>http://cycling74.com/forums/topic/singleton-issues/#post-103526</guid>
					<title><![CDATA[Re: Singleton issues.]]></title>
					<link>http://cycling74.com/forums/topic/singleton-issues/#post-103526</link>
					<pubDate>Fri, 04 May 2007 06:21:29 +0000</pubDate>
					<dc:creator>Matthew Aidekman</dc:creator>

					<description>
						<![CDATA[
						<p>I&#8217;ve uploaded a set of files with this exact code.</p>
<p>when I instantiate sub1 and sub2, this is what appears in the max window.   each SubElement appears to be in its own world where singleton must be reinstantiated.  I would assume this is expected behaviour and its my &#8220;fault.&#8221;</p>
<p>Sub1Element constructor: GlobalTest_Singleton@7e6081<br />
GlobalTest_Sub1 gui= GlobalTest_Singleton@7e6081<br />
GlobalTest_Sub1 gui2= GlobalTest_Singleton@7e6081<br />
Sub1Element constructor: GlobalTest_Singleton@fff2dc<br />
GlobalTest_Sub2 gui= GlobalTest_Singleton@fff2dc<br />
GlobalTest_Sub2 gui2= GlobalTest_Singleton@fff2dc</p>
						]]>
					</description>

					
					
				</item>

			
				<item>
					<guid>http://cycling74.com/forums/topic/singleton-issues/#post-103527</guid>
					<title><![CDATA[Re: Singleton issues.]]></title>
					<link>http://cycling74.com/forums/topic/singleton-issues/#post-103527</link>
					<pubDate>Fri, 04 May 2007 08:14:53 +0000</pubDate>
					<dc:creator>Ollie Bown</dc:creator>

					<description>
						<![CDATA[
						<p>I ran your classes and got the behaviour you wanted (the expected  <br />
behaviour) rather than the behaviour you report. Everything is  <br />
pointing to the same GlobalTest_Singleton. Looks like your code is  <br />
fine but your test patch is doing something funny. Are you zapping or  <br />
something?</p>
<p>Ollie</p>
<p>On 4 May 2007, at 07:21, Matthew Aidekman wrote:</p>
<p>> I&#8217;ve uploaded a set of files with this exact code.<br />
><br />
> when I instantiate sub1 and sub2, this is what appears in the max  <br />
> window.   each SubElement appears to be in its own world where  <br />
> singleton must be reinstantiated.  I would assume this is expected  <br />
> behaviour and its my &#8220;fault.&#8221;<br />
><br />
> Sub1Element constructor: GlobalTest_Singleton@7e6081<br />
> GlobalTest_Sub1 gui= GlobalTest_Singleton@7e6081<br />
> GlobalTest_Sub1 gui2= GlobalTest_Singleton@7e6081<br />
> Sub1Element constructor: GlobalTest_Singleton@fff2dc<br />
> GlobalTest_Sub2 gui= GlobalTest_Singleton@fff2dc<br />
> GlobalTest_Sub2 gui2= GlobalTest_Singleton@fff2dc<br />
><br />
> <to max board.zip></to></p>
						]]>
					</description>

					
					
				</item>

			
				<item>
					<guid>http://cycling74.com/forums/topic/singleton-issues/#post-103528</guid>
					<title><![CDATA[Re: Singleton issues.]]></title>
					<link>http://cycling74.com/forums/topic/singleton-issues/#post-103528</link>
					<pubDate>Fri, 04 May 2007 09:10:21 +0000</pubDate>
					<dc:creator>Ollie Bown</dc:creator>

					<description>
						<![CDATA[
						<p>Oh, here&#8217;s a better answer: <a href="http://www.cycling74.com/story/" rel="nofollow">http://www.cycling74.com/story/</a> <br />
2006/1/30/114359/484</p>
<p>If I simultaneously &#8216;zap&#8217; your two classes, or if one of the class  <br />
files is recompiled and the object then reloaded, then they do start  <br />
to report different singletons, which makes sense in light of the  <br />
above article. Presumably the MXJClassLoader for each class also  <br />
looks after the classes being referenced by it, resulting in two  <br />
GlobalTest_Singleton classes.</p>
<p>I&#8217;m doing stuff with static variables being used across a set of  <br />
classes too, and boring though it is, I&#8217;ve always felt safer quitting  <br />
and restarting Max when I really want to be sure that something  <br />
static is doing what I expected it to do. But now I&#8217;m curious,  <br />
presumably you can make your own MXJClassLoader and force it to load  <br />
a specified set of classes, or a package. Hmmm.</p>
<p>Ollie</p>
<p>On 4 May 2007, at 09:14, Oliver Bown wrote:</p>
<p>> I ran your classes and got the behaviour you wanted (the expected  <br />
> behaviour) rather than the behaviour you report. Everything is  <br />
> pointing to the same GlobalTest_Singleton. Looks like your code is  <br />
> fine but your test patch is doing something funny. Are you zapping  <br />
> or something?<br />
><br />
> Ollie<br />
><br />
> On 4 May 2007, at 07:21, Matthew Aidekman wrote:<br />
><br />
>> I&#8217;ve uploaded a set of files with this exact code.<br />
>><br />
>> when I instantiate sub1 and sub2, this is what appears in the max  <br />
>> window.   each SubElement appears to be in its own world where  <br />
>> singleton must be reinstantiated.  I would assume this is expected  <br />
>> behaviour and its my &#8220;fault.&#8221;<br />
>><br />
>> Sub1Element constructor: GlobalTest_Singleton@7e6081<br />
>> GlobalTest_Sub1 gui= GlobalTest_Singleton@7e6081<br />
>> GlobalTest_Sub1 gui2= GlobalTest_Singleton@7e6081<br />
>> Sub1Element constructor: GlobalTest_Singleton@fff2dc<br />
>> GlobalTest_Sub2 gui= GlobalTest_Singleton@fff2dc<br />
>> GlobalTest_Sub2 gui2= GlobalTest_Singleton@fff2dc<br />
>><br />
>> <to max board.zip><br />
></to></p>
						]]>
					</description>

					
					
				</item>

			
				<item>
					<guid>http://cycling74.com/forums/topic/singleton-issues/#post-103529</guid>
					<title><![CDATA[Re: Singleton issues.]]></title>
					<link>http://cycling74.com/forums/topic/singleton-issues/#post-103529</link>
					<pubDate>Fri, 04 May 2007 09:17:04 +0000</pubDate>
					<dc:creator>Owen Green</dc:creator>

					<description>
						<![CDATA[
						<p>Hi Matt,</p>
<p>What version of Max are you on? Under an older classloading scheme, this <br />
approach wouldn&#8217;t work at all. Under the current one, it should, but <br />
you&#8217;re well off closing and opening the patch, or zapping everything, or <br />
even restarting max to make sure everything&#8217;s loaded from the same <br />
classloader.</p>
<p>&#8211; <br />
Owen</p>
<p>Matthew Aidekman wrote:<br />
> Ok I&#8217;m going to try and explain this as succinctly as possible.  it<br />
> may be a brain teaser.   I&#8217;m a beginner javamaxer. In fact I just<br />
> learned what a singleton was.   What I&#8217;m doing in reality is editing<br />
> the Java JitterGui. but I&#8217;ve mangled it pretty fearsome.  I&#8217;m<br />
> thinking what I need is an ?interface? of some sort.</p>
						]]>
					</description>

					
					
				</item>

			
				<item>
					<guid>http://cycling74.com/forums/topic/singleton-issues/#post-103530</guid>
					<title><![CDATA[Re: Singleton issues.]]></title>
					<link>http://cycling74.com/forums/topic/singleton-issues/#post-103530</link>
					<pubDate>Fri, 04 May 2007 15:18:52 +0000</pubDate>
					<dc:creator>Matthew Aidekman</dc:creator>

					<description>
						<![CDATA[
						<p>I&#8217;m on <br />
os 10.4.8  <br />
PB G4<br />
4.6.2</p>
<p>I will look into classloader zap etc..  </p>
<p>you guys rock. I can&#8217;t believe someone actually tested that gobblety gook.</p>
						]]>
					</description>

					
					
				</item>

			
				<item>
					<guid>http://cycling74.com/forums/topic/singleton-issues/#post-103531</guid>
					<title><![CDATA[Re: Singleton issues.]]></title>
					<link>http://cycling74.com/forums/topic/singleton-issues/#post-103531</link>
					<pubDate>Fri, 04 May 2007 15:23:52 +0000</pubDate>
					<dc:creator>Owen Green</dc:creator>

					<description>
						<![CDATA[
						<p>Matthew Aidekman wrote:<br />
> I&#8217;m on <br />
> os 10.4.8  <br />
> PB G4<br />
> 4.6.2<br />
> <br />
> I will look into classloader zap etc..  </p>
<p>Given that you&#8217;re up to date mxj-wise, can you verify Ollie&#8217;s experience <br />
that it works if you restart max? All instances should then share a <br />
classloader, and static behaviour should work across objects.</p>
<p>&#8211; <br />
Owen</p>
						]]>
					</description>

					
					
				</item>

			
				<item>
					<guid>http://cycling74.com/forums/topic/singleton-issues/#post-103532</guid>
					<title><![CDATA[Re: Singleton issues.]]></title>
					<link>http://cycling74.com/forums/topic/singleton-issues/#post-103532</link>
					<pubDate>Fri, 04 May 2007 15:43:10 +0000</pubDate>
					<dc:creator>Matthew Aidekman</dc:creator>

					<description>
						<![CDATA[
						<p>SUCCESS! Java schedules pee breaks for the programmer! GENUIS!  </p>
<p>/looking into zap</p>
						]]>
					</description>

					
					
				</item>

			
				<item>
					<guid>http://cycling74.com/forums/topic/singleton-issues/#post-103533</guid>
					<title><![CDATA[Re: Singleton issues.]]></title>
					<link>http://cycling74.com/forums/topic/singleton-issues/#post-103533</link>
					<pubDate>Fri, 04 May 2007 16:35:52 +0000</pubDate>
					<dc:creator>Matthew Aidekman</dc:creator>

					<description>
						<![CDATA[
						<p>ollie, if you figure that thing out with the classloaders, please let me know,   I&#8217;m planning on scripting these objects in and out of existence so it would be very helpful.</p>
<p>unfortunately, I&#8217;m just not at that level yet.  I looked up classloader, I don&#8217;t understand it. but I will make my way through it more slowly.</p>
						]]>
					</description>

					
					
				</item>

			
				<item>
					<guid>http://cycling74.com/forums/topic/singleton-issues/#post-103534</guid>
					<title><![CDATA[Re: Singleton issues.]]></title>
					<link>http://cycling74.com/forums/topic/singleton-issues/#post-103534</link>
					<pubDate>Fri, 04 May 2007 16:45:08 +0000</pubDate>
					<dc:creator>Ollie Bown</dc:creator>

					<description>
						<![CDATA[
						<p>The quick fix, I think, would be just not to use zap or anything  <br />
funny when you&#8217;re on stage. Once you&#8217;ve loaded the class and it has  <br />
set its static variables up, it&#8217;s not going anywhere. It works for me  <br />
(as far as I&#8217;m aware!).</p>
<p>O</p>
<p>On 4 May 2007, at 17:35, Matthew Aidekman wrote:</p>
<p>><br />
> ollie, if you figure that thing out with the classloaders, please  <br />
> let me know,   I&#8217;m planning on scripting these objects in and out  <br />
> of existence so it would be very helpful.<br />
><br />
> unfortunately, I&#8217;m just not at that level yet.  I looked up  <br />
> classloader, I don&#8217;t understand it. but I will make my way through  <br />
> it more slowly.</p>
						]]>
					</description>

					
					
				</item>

					
		
	</channel>
	</rss>

