commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Sciss <cont...@sciss.de>
Subject Re: [javaflow] Re: getting javaflow
Date Tue, 04 Dec 2007 17:53:54 GMT
hello torsten,

i have another question: how can i include objects other than  
primitives into the continuation storage? in this example:

		final Runnable r = new Runnable() {
			public void run()
			{
				final java.util.Random rnd = new java.util.Random();
				int value	= 500;
				int d;
				
				while( true ) {
					d = rnd.nextInt( 51 ) - 25;
					System.out.println( "val = " + value + "; d = " + d );
					value += d;
					if( value < 0 ) {
						value += 1001;
					} else if( value > 1000 ) {
						value -= 1001;
					}
					Continuation.suspend();
				}
			}
		};

		final Continuation c = Continuation.startSuspendedWith( r );
		Continuation d;

		System.out.println( "First run" );
		d = c;
		for( int i = 0; i < 5; i++ ) d = Continuation.continueWith( d );

		System.out.println( "Second run" );
		d = c;
		for( int i = 0; i < 5; i++ ) d = Continuation.continueWith( d );

... the output is something like:

	First run
	val = 500; d = 11
	val = 511; d = 5
	val = 516; d = -19
	val = 497; d = 11
	val = 508; d = 21
	Second run
	val = 500; d = -25
	val = 475; d = -6
	val = 469; d = -15
	val = 454; d = -11
	val = 443; d = 9

so obviously 'value' got restored, but the random generator doesn't  
restore its seed. so can i make javaflow store the internal state of  
'rnd', too?

thanks, -sciss-





Am 04.12.2007 um 16:04 schrieb Torsten Curdt:

> Great! ...but still added the example to my TODO.
> Javaflow needs some polishing anyway.
>
> cheers
> --
> Torsten
>
> On 04.12.2007, at 14:51, Sciss wrote:
>
>> thank you torsten,
>>
>> putting my runnable in a dedicated package and using  
>> addLoaderPackageRoot("your.package.the.runnable.is.in") did it!
>>
>> now going back to experimentation ;-9
>>
>> ciao, -sciss-
>>
>>
>> Am 03.12.2007 um 12:23 schrieb Torsten Curdt:
>>
>>> Seems like I badly need to look into providing the tutorial  
>>> example to just run out of the box.
>>>
>>> On the first glance your try on the class loading seems a bit  
>>> unorthodox but should still work. (I never used the classloader  
>>> but always used javaflow through jci) ...but looking at the code  
>>> I'd assume you also need to tell the classloader what classes to  
>>> instrument. You might want to try
>>>
>>>   addLoaderPackageRoot("your.package.the.runnable.is.in");
>>>
>>> or set
>>>
>>>   setParentFirst(false);
>>>
>>> Let me know if that helped.
>>>
>>> cheers
>>> --
>>> Torsten
>>>
>>> -------------------------------------------------------------------- 
>>> -
>>> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
>>> For additional commands, e-mail: user-help@commons.apache.org
>>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
>> For additional commands, e-mail: user-help@commons.apache.org
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
> For additional commands, e-mail: user-help@commons.apache.org
>


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org


Mime
View raw message