<?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: newbie in threads question</title>
		<atom:link href="http://cycling74.com/forums/topic/newbie-in-threads-question/feed" rel="self" type="application/rss+xml" />
		<link>http://cycling74.com/forums/topic/newbie-in-threads-question/feed</link>
		<description></description>
		<pubDate>Thu, 20 Jun 2013 03:39:10 +0000</pubDate>
		<generator>http://bbpress.org/?v=2.2.4</generator>
		<language></language>

		
														
					
				<item>
					<guid>http://cycling74.com/forums/topic/newbie-in-threads-question/#post-38549</guid>
					<title><![CDATA[newbie in threads question]]></title>
					<link>http://cycling74.com/forums/topic/newbie-in-threads-question/#post-38549</link>
					<pubDate>Mon, 23 Jun 2008 14:44:16 +0000</pubDate>
					<dc:creator>Alexandre</dc:creator>

					<description>
						<![CDATA[
						<p>Hi,</p>
<p>I&#8217;m looking for a way to stop a &#8220;process&#8221; or a &#8220;thread&#8221;. i have a method in mxj which is called when i change the value of a number box in max, and this method executes a drawing-thread to draw something which can, sometimes, be slow. (if a change the value very fast in max, the method doesn&#8217;t have time to compute everytime) </p>
<p>So, i&#8217;d like, that, when the method is called, it tests to see if the drawing-thread is already running (from a previous method call), and if it&#8217;s the case, that it delete the thread and restart it. i&#8217;m not sure how to do that. first i managed to create a thread inside my method, with :</p>
<p>public void redraw_because_value_changed( int value_from_max ) {<br />
    &#8230;<br />
    ( new Thread() { public void run() {<br />
         &#8230;// the drawing stuff &#8230;<br />
    }}).start();<br />
}</p>
<p>This works fine, but will create many threads if the drawing is slow while i change the value in max, causing slow down. But then i tried to name the thread, and delete it before restarting a new one, and first, this works a little, but when i change my value very fast in max5, it crashes. :</p>
<p>
Thread curveThread; </p>
<p>public void redraw_because_value_changed( int value_from_max ) {<br />
    &#8230;<br />
    curveThread = null ;<br />
    ( curveThread =  new Thread() { public void run() {<br />
          &#8230;// the drawing stuff &#8230;<br />
    }}).start();<br />
}</p>
<p>
I not sure to understand well how to manage this. In the &#8220;flies.java&#8221; example, there&#8217;s an other example on managing threads, but i can&#8217;t figure out how it works plus the need in &#8220;flies&#8221; is different.</p>
<p>
Thanks a lot for any help.</p>
<p>Alexandre.</p>
						]]>
					</description>

					
					
				</item>

			
				<item>
					<guid>http://cycling74.com/forums/topic/newbie-in-threads-question/#post-134553</guid>
					<title><![CDATA[Re: newbie in threads question]]></title>
					<link>http://cycling74.com/forums/topic/newbie-in-threads-question/#post-134553</link>
					<pubDate>Mon, 23 Jun 2008 16:21:53 +0000</pubDate>
					<dc:creator>Siska Ádám</dc:creator>

					<description>
						<![CDATA[
						<p>Hi Alexandre,</p>
<p>
to me this problem is more related to general threading issues than to <br />
mxj programming. I think the Sun Tutorial on concurrency,</p>
<p><a href="http://java.sun.com/docs/books/tutorial/essential/concurrency/index.html" rel="nofollow">http://java.sun.com/docs/books/tutorial/essential/concurrency/index.html</a></p>
<p>would be a good starting point for you. In my opinion, it will be far <br />
enough at this point for you to read it just until the end of the first <br />
big paragraph (called Thread Objects).</p>
<p>
Hope this helps,<br />
Adam</p>
<p>
____________________<br />
Siska Ádám<br />
+36 (70) 207-63-85</p>
<p><a href="http://www.sadam.hu/" rel="nofollow">http://www.sadam.hu/</a></p>
<p>
Alexandre wrote:<br />
> Hi,<br />
><br />
> I&#8217;m looking for a way to stop a &#8220;process&#8221; or a &#8220;thread&#8221;. i have a method in mxj which is called when i change the value of a number box in max, and this method executes a drawing-thread to draw something which can, sometimes, be slow. (if a change the value very fast in max, the method doesn&#8217;t have time to compute everytime) <br />
><br />
> So, i&#8217;d like, that, when the method is called, it tests to see if the drawing-thread is already running (from a previous method call), and if it&#8217;s the case, that it delete the thread and restart it. i&#8217;m not sure how to do that. first i managed to create a thread inside my method, with :<br />
><br />
> public void redraw_because_value_changed( int value_from_max ) {<br />
>     &#8230;<br />
>     ( new Thread() { public void run() {<br />
>          &#8230;// the drawing stuff &#8230;<br />
>     }}).start();<br />
> }<br />
><br />
> This works fine, but will create many threads if the drawing is slow while i change the value in max, causing slow down. But then i tried to name the thread, and delete it before restarting a new one, and first, this works a little, but when i change my value very fast in max5, it crashes. :<br />
><br />
><br />
> Thread curveThread; <br />
><br />
> public void redraw_because_value_changed( int value_from_max ) {<br />
>     &#8230;<br />
>     curveThread = null ;<br />
>     ( curveThread =  new Thread() { public void run() {<br />
>           &#8230;// the drawing stuff &#8230;<br />
>     }}).start();<br />
> }<br />
><br />
><br />
> I not sure to understand well how to manage this. In the &#8220;flies.java&#8221; example, there&#8217;s an other example on managing threads, but i can&#8217;t figure out how it works plus the need in &#8220;flies&#8221; is different.<br />
><br />
><br />
> Thanks a lot for any help.<br />
><br />
> Alexandre.<br />
><br />
><br />
>   </p>
						]]>
					</description>

					
					
				</item>

			
				<item>
					<guid>http://cycling74.com/forums/topic/newbie-in-threads-question/#post-134554</guid>
					<title><![CDATA[Re: newbie in threads question]]></title>
					<link>http://cycling74.com/forums/topic/newbie-in-threads-question/#post-134554</link>
					<pubDate>Mon, 23 Jun 2008 17:39:23 +0000</pubDate>
					<dc:creator>Adam Murray</dc:creator>

					<description>
						<![CDATA[
						<p>To achieve good performance, you should probably avoid deleting and recreating the same kind of object when possible. In your case, it may make more sense to set a volatile variable in the Thread like &#8220;runAgain&#8221;, which the thread will check after it&#8217;s done drawing and loop back to the beginning of the draw routine if runAgain==true. Or maybe you can interrupt() your Thread and then restart it, instead of delete/recreate.</p>
<p>You may find this information helpful:</p>
<p><a href="http://java.sun.com/javase/6/docs/technotes/guides/concurrency/threadPrimitiveDeprecation.html" rel="nofollow">http://java.sun.com/javase/6/docs/technotes/guides/concurrency/threadPrimitiveDeprecation.html</a></p>
<p>Also, on the Max side, you should consider using a speedlim object between your number box and mxj.</p>
						]]>
					</description>

					
					
				</item>

			
				<item>
					<guid>http://cycling74.com/forums/topic/newbie-in-threads-question/#post-134555</guid>
					<title><![CDATA[Re: newbie in threads question]]></title>
					<link>http://cycling74.com/forums/topic/newbie-in-threads-question/#post-134555</link>
					<pubDate>Mon, 23 Jun 2008 18:10:49 +0000</pubDate>
					<dc:creator>Alexandre</dc:creator>

					<description>
						<![CDATA[
						<p>Thanks for your help, Adam,</p>
<p>In fact, looking completly at your links, it&#8217;s looking like there no way to stop a thread without testing inside itself, with methods like &#8220;Thread.interrupted&#8221; or &#8220;catch (InterruptedException e)&#8221;:</p>
<p>&#8220;What if a thread goes a long time without invoking a method that throws InterruptedException? Then it must periodically invoke Thread.interrupted, which returns true if an interrupt has been received.&#8221;  ( <a href="http://java.sun.com/docs/books/tutorial/essential/concurrency/interrupt.html" rel="nofollow">http://java.sun.com/docs/books/tutorial/essential/concurrency/interrupt.html</a> )</p>
<p>mmh.. This stop() method from &#8220;java.lang.Thread&#8221; , is now deprecated for complicated reasons. So, if i have to test from inside my loops, to continue or to &#8220;break&#8221;, i just can use effectivly a kind of &#8220;runAgain&#8221; booleen, defined in the class (or &#8220;volatile&#8221;?.. an other concept to learn for me), which can ask the thread to stop. (when the booleen is tested at each end of my heavy-drawing-loop) Without any need to bother myself with new methods with which i&#8217;m not confortable with.</p>
<p>But, is it really sure that there no way to stop a thread without introducing testing stuff periodically in the thread itself ?</p>
<p>Well, i might post this question to a java forum, but for now, i just realised that a big part of my drawing time was, actually, the call of com.cycling74.jitter.JitterMatrix.copyBufferedImage : 100 milliseconds!&#8230; (for a 1200*700 image)<br />
I posted a new topic for this new problem.</p>
<p>Thanks,<br />
Alexandre</p>
						]]>
					</description>

					
					
				</item>

			
				<item>
					<guid>http://cycling74.com/forums/topic/newbie-in-threads-question/#post-134556</guid>
					<title><![CDATA[Re: newbie in threads question]]></title>
					<link>http://cycling74.com/forums/topic/newbie-in-threads-question/#post-134556</link>
					<pubDate>Mon, 23 Jun 2008 18:16:03 +0000</pubDate>
					<dc:creator>Owen Green</dc:creator>

					<description>
						<![CDATA[
						<p>Alexandre wrote:<br />
> But, is it really sure that there no way to stop a thread without<br />
> introducing testing stuff periodically in the thread itself ?</p>
<p>Yes &#8211; the reason stop() was deprecated was partly because the only way <br />
of telling if it&#8217;s safe to stop a thread is from within.</p>
<p>&#8211; <br />
Owen</p>
						]]>
					</description>

					
					
				</item>

			
				<item>
					<guid>http://cycling74.com/forums/topic/newbie-in-threads-question/#post-134557</guid>
					<title><![CDATA[Re: newbie in threads question]]></title>
					<link>http://cycling74.com/forums/topic/newbie-in-threads-question/#post-134557</link>
					<pubDate>Mon, 23 Jun 2008 21:06:56 +0000</pubDate>
					<dc:creator>nick rothwell / cassiel</dc:creator>

					<description>
						<![CDATA[
						<p>
On 23 Jun 2008, at 19:10, Alexandre wrote:</p>
<p>> mmh.. This stop() method from &#8220;java.lang.Thread&#8221; , is now deprecated  <br />
> for complicated reasons.</p>
<p>Complicated, but quite important: if you start writing multithreaded  <br />
code you&#8217;ll have to understand semaphores. In other words, threading  <br />
is subtle and quick to anger. But if you keep it simple and keep a  <br />
clear head, it&#8217;s manageable.</p>
<p>	&#8211; N.</p>
<p>
Nick Rothwell / Cassiel.com Limited<br />
<a href="http://www.cassiel.com" rel="nofollow">http://www.cassiel.com</a><br />
<a href="http://www.myspace.com/cassieldotcom" rel="nofollow">http://www.myspace.com/cassieldotcom</a><br />
<a href="http://www.last.fm/music/cassiel" rel="nofollow">http://www.last.fm/music/cassiel</a><br />
<a href="http://www.reverbnation.com/cassiel" rel="nofollow">http://www.reverbnation.com/cassiel</a><br />
<a href="http://www.linkedin.com/in/cassiel" rel="nofollow">http://www.linkedin.com/in/cassiel</a><br />
<a href="http://www.loadbang.net" rel="nofollow">http://www.loadbang.net</a></p>
						]]>
					</description>

					
					
				</item>

			
				<item>
					<guid>http://cycling74.com/forums/topic/newbie-in-threads-question/#post-134558</guid>
					<title><![CDATA[Re: newbie in threads question]]></title>
					<link>http://cycling74.com/forums/topic/newbie-in-threads-question/#post-134558</link>
					<pubDate>Mon, 23 Jun 2008 22:04:37 +0000</pubDate>
					<dc:creator>Alexandre</dc:creator>

					<description>
						<![CDATA[
						<p>ok i think i understand better now. thanks.</p>
						]]>
					</description>

					
					
				</item>

					
		
	</channel>
	</rss>

