Hi Francisco,
0
In VideoTransmit.java (a sample code of JMF), JMF engineer use the following
way to "sleep a main proccess" :
public static void main(String [] args) {
...
try {
Thread.currentThread().sleep(30000); //30 seconds
} catch (InterruptedException ie) { ... }
...
System.exit(0);
}
1
In AVTransmit.java.java (another sample code of JMF), JMF engineer use
the following way to "block a main proccess":
...
/****************************************************************
* Convenience methods to handle processor's state changes.
****************************************************************/
private Integer stateLock = new Integer(0);
private boolean failed = false;
Integer getStateLock() {
return stateLock;
}
void setFailed() {
failed = true;
}
private synchronized boolean waitForState(Processor p, int state) {
p.addControllerListener(new StateListener());
failed = false;
// Call the required method on the processor
if (state == Processor.Configured) {
p.configure();
} else if (state == Processor.Realized) {
p.realize();
}
// Wait until we get an event that confirms the
// success of the method, or a failure event.
// See StateListener inner class
while (p.getState() < state && !failed) {
synchronized (getStateLock()) {
try {
getStateLock().wait();
} catch (InterruptedException ie) {
return false;
}
}
}
if (failed)
return false;
else
return true;
}
/****************************************************************
* Inner Classes
****************************************************************/
class StateListener implements ControllerListener {
public void controllerUpdate(ControllerEvent ce) {
// If there was an error during configure or
// realize, the processor will be closed
if (ce instanceof ControllerClosedEvent)
setFailed();
// All controller events, send a notification
// to the waiting thread in waitForState method.
if (ce instanceof ControllerEvent) {
synchronized (getStateLock()) {
getStateLock().notifyAll();
}
}
}
}
/****************************************************************
* Sample Usage for AVTransmit class
****************************************************************/
( * In above, the Processor is a "audio/video encoder". )
2
You can get these two sample codes from JMF WEB site.
Bo
Sept.29, 2000
Francisco Jesus Castillo Pinazo wrote:
> I need to sleep a main process in java, i try to do this.wait(X) but it
> don�t compile, I Knew how to sleep a thread but i dont Known how to sleep a
> main proccess.
>
> Thanks for your time.
>
> ___________________________________________________________________________
> To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
> of the message "signoff SERVLET-INTEREST".
>
> Archives: http://archives.java.sun.com/archives/servlet-interest.html
> Resources: http://java.sun.com/products/servlet/external-resources.html
> LISTSERV Help: http://www.lsoft.com/manuals/user/user.html
___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".
Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html