RE: Scheduling with WOTimer
RE: Scheduling with WOTimer
- Subject: RE: Scheduling with WOTimer
- From: "Xia, Wen" <email@hidden>
- Date: Wed, 10 Mar 2004 08:43:32 -0800
Hi Dirk, thank you for your explanation. I tried it and it works now.
-----Original Message-----
From: Dirk Bajohr [mailto:email@hidden]
Sent: Wednesday, March 10, 2004 12:51 AM
To: Xia, Wen
Subject: Re: Scheduling with WOTimer
Hi,
what Jonathan wanted to say was using the static method
WOApplication.application()
in your custom class, not extending the application class.
The variables that you set in another thread should be synchronized.
Do something like this in your custom class:
import com.webobjects.appserver.WOApplication;
class MyClass extends Thread {
...
public void myMethod() {
// application() is a static method in class WOApplication
// you can use it anywhere in your code to get the current
// application, you only need to typecast it to your custom
// application class.
Application app = (Application)WOApplication.application();
app.setVariable(...);
}
...
}
And in your application:
...
public synchronized setVariable(Object variable) {
this.variable = variable;
}
...
Hope that helps,
Dirk
Am 10.03.2004 um 00:46 schrieb Xia, Wen:
> Yeah, I did try to use the static method application(). Here is what
> I did:
> My timer extends the Application class. Inside timer, I tried to get
> the
> current WOApplication class using "static Application ap =
> (Application)
> application();" And the timer is created in the constructor of the
> Application class. When I run the application, I encounter the
> following
> error message. Did I do something wrong here? Please advise. Thank
> you.
>
> [2004-03-09 15:11:12 PST] <main> Unable to establish a connection to
> port
> 50442 on this host. Perhaps this port is already in use by another
> WebObjects application instance.
> [2004-03-09 15:11:12 PST] <main> <WOApplication>: Cannot be
> initialized.null
> [2004-03-09 15:11:12 PST] <main> A fatal exception occurred: null:
> <WOApplication>: Cannot be initialized.
> [2004-03-09 15:11:12 PST] <main>
> com.webobjects.foundation.NSForwardException for
> com.webobjects.foundation.NSForwardException for
> java.net.BindException:
> Address already in use
> at java.net.PlainSocketImpl.socketBind(Native Method)
> at java.net.PlainSocketImpl.bind(PlainSocketImpl.java:331)
> at java.net.ServerSocket.bind(ServerSocket.java:309)
> at java.net.ServerSocket.<init>(ServerSocket.java:183)
> at
> com.webobjects.appserver._private.WODefaultAdaptor._initServerSocket(WO
> Defau
> ltAdaptor.java:157)
> at
> com.webobjects.appserver._private.WODefaultAdaptor.<init>(WODefaultAdap
> tor.j
> ava:140)
> at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native
> Method)
> at
> sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructor
> Acces
> sorImpl.java:39)
> at
> sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingCon
> struc
> torAccessorImpl.java:27)
> at java.lang.reflect.Constructor.newInstance(Constructor.java:274)
> at
> com.webobjects.foundation._NSUtilities.instantiateObject(_NSUtilities.j
> ava:5
> 29)
> at
> com.webobjects.appserver.WOApplication.adaptorWithName(WOApplication.ja
> va:90
> 9)
> at
> com.webobjects.appserver.WOApplication._initAdaptors(WOApplication.java
> :955)
> at
> com.webobjects.appserver.WOApplication.<init>(WOApplication.java:509)
> at Application.<init>(Application.java:34)
> at dpScheduler.<init>(dpScheduler.java:22)
> at Application.<init>(Application.java:49)
> at dpScheduler.<init>(dpScheduler.java:22)
> at Application.<init>(Application.java:49)
> at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native
> Method)
> at
> sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructor
> Acces
> sorImpl.java:39)
> at
> sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingCon
> struc
> torAccessorImpl.java:27
> at java.lang.reflect.Constructor.newInstance(Constructor.java:274)
> at java.lang.Class.newInstance0(Class.java:306)
> at java.lang.Class.newInstance(Class.java:259)
> at
> com.webobjects.appserver.WOApplication.main(WOApplication.java:296)
> at Application.main(Application.java:30)
> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> at
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.ja
> va:39
> )
> at
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccesso
> rImpl
> .java:25)
> at java.lang.reflect.Method.invoke(Method.java:324)
> at com.webobjects._bootstrap.WOBootstrap.main(WOBootstrap.java:71)
> StateNet has exited with status 1.}
>
> -----Original Message-----
> From: Jonathan Rochkind [mailto:email@hidden]
> Sent: Tuesday, March 09, 2004 3:05 PM
> To: Xia, Wen; 'WOdev List List'
> Subject: RE: Scheduling with WOTimer
>
>
> No, the static method application() in WOApplication.
>
> WOApplication:
> public static WOApplication application();
>
> Can be called from anywhere. It's a static method. Returns the
> current WOApplication class. You may have to sub-class it to your
> custom sub-class, typically called 'Application'.
>
> In a mulit-threaded scenario (which a timer certainly is), you should
> ensure thread safe access to the variables you plan on modifying in
> Application.
>
> --Jonathan
> _______________________________________________
> webobjects-dev mailing list | email@hidden
> Help/Unsubscribe/Archives:
> http://www.lists.apple.com/mailman/listinfo/webobjects-dev
> Do not post admin requests to the list. They will be ignored.
>
>
--
Dirk Bajohr
iSOLUTION - Individuelle Software fuer moderne Kommunikation
Hauptstr. 50
53757 Sankt Augustin
T +49 2241 921567-0
F +49 2241 921567-89
http://www.isolution.de
_______________________________________________
webobjects-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/webobjects-dev
Do not post admin requests to the list. They will be ignored.