Set TimeOut for SwingWorker

nice day,
1/ how can I get real Html size in kB with intention to set as maxValue to ProgressMonitor
2/ how can I set/synchronize current valueOfDownLoadedHtml in kB to ProgressMonitor throught downloading Html content
3/ how can I set TimeOut for this Tast, (maybe ... could I use Timer)
import java.awt.BorderLayout;
import java.awt.Insets;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.net.URLConnection;
import java.nio.charset.Charset;
import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.ProgressMonitor;
import javax.swing.SwingWorker;
public class ProgressMonitorDemo extends JPanel implements ActionListener, PropertyChangeListener {
    private static final long serialVersionUID = 1L;
    private ProgressMonitor progressMonitor;
    private JButton startButton;
    private JTextArea taskOutput;
    private Task task;
    private int sizeIn_kB = 0;
    class Task extends SwingWorker<Void, Void> {
        private String str;
        int progress = 0;
        public Task(String str) {
            this.str = str;
        @Override
        public Void doInBackground() {
            if (str.equals("Loads")) {
                addBackgroundLoadsData();
                setProgress(0);
                while (progress < sizeIn_kB && !isCancelled()) {
                    progress += sizeIn_kB;
                    setProgress(Math.min(progress, sizeIn_kB));
            return null;
        @Override
        public void done() {
            if (str.equals("Loads")) {
                Toolkit.getDefaultToolkit().beep();
                startButton.setEnabled(true);
                progressMonitor.setProgress(0);
    public void addBackgroundLoadsData() {
        InputStream in = null;
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        String charset ="";
        try {
            String UrlString = "http://java.sun.com/";
            URL url = new URL(UrlString);
            URLConnection conn = url.openConnection();
            sizeIn_kB = conn.getContentLength();
            charset = conn.getContentEncoding();
            conn.setRequestProperty("Accept-Charset", charset);
            in = conn.getInputStream();
            int len;
            byte[] buf = new byte[1024];
            while ((len = in.read(buf)) > 0) {
                bos.write(buf, 0, len);
            in.close();
            String charEncoding = Charset.defaultCharset().name();
            //String fileEncoding = System.getProperty("file.encoding");
            //System.out.println("File Encoding: " + fileEncoding);
            //System.out.println("Char Encoding: " + charEncoding);
            //System.out.println("Char Encoding: " + Charset.availableCharsets());
            charEncoding = "cp1250";
            String groupImport = new String(bos.toByteArray(), charEncoding);
            conn = null;
        } catch (IOException ioException) {
            ioException.printStackTrace();
            JOptionPane.showMessageDialog(null, ioException.getMessage(), "Htlm error", JOptionPane.ERROR_MESSAGE);
        } catch (StringIndexOutOfBoundsException ioException) {
            ioException.printStackTrace();
            JOptionPane.showMessageDialog(null, ioException.getMessage(), "InputStream error", JOptionPane.ERROR_MESSAGE);
    public ProgressMonitorDemo() {
        super(new BorderLayout());
        startButton = new JButton("Start");
        startButton.setActionCommand("start");
        startButton.addActionListener(this);
        taskOutput = new JTextArea(5, 20);
        taskOutput.setMargin(new Insets(5, 5, 5, 5));
        taskOutput.setEditable(false);
        add(startButton, BorderLayout.PAGE_START);
        add(new JScrollPane(taskOutput), BorderLayout.CENTER);
        setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20));
    @Override
    public void actionPerformed(ActionEvent evt) {
        progressMonitor = new ProgressMonitor(ProgressMonitorDemo.this, "Running a Long Task", "", 0, 100);
        progressMonitor.setProgress(0);
        task = new Task("Loads");
        task.addPropertyChangeListener(this);
        task.execute();
        startButton.setEnabled(false);
    @Override
    public void propertyChange(PropertyChangeEvent evt) {
        if ("progress" == null ? evt.getPropertyName() == null : "progress".equals(evt.getPropertyName())) {
            int progress = (Integer) evt.getNewValue();
            progressMonitor.setProgress(progress);
            String message = String.format("Completed %d%%.\n", progress);
            progressMonitor.setNote(message);
            taskOutput.append(message);
            if (progressMonitor.isCanceled() || task.isDone()) {
                Toolkit.getDefaultToolkit().beep();
                if (progressMonitor.isCanceled()) {
                    task.cancel(true);
                    taskOutput.append("Task canceled.\n");
                } else {
                    taskOutput.append("Task completed.\n");
                startButton.setEnabled(true);
    private static void createAndShowGUI() {
        JFrame frame = new JFrame("ProgressMonitorDemo");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        JComponent newContentPane = new ProgressMonitorDemo();
        newContentPane.setOpaque(true);
        frame.setContentPane(newContentPane);
        frame.pack();
        frame.setVisible(true);
    public static void main(String[] args) {
        javax.swing.SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                createAndShowGUI();
}

See the session-descriptor element of weblogic.xml deployment descriptor:
http://download.oracle.com/docs/cd/E21764_01/web.1111/e13712/weblogic_xml.htm#i1071981

Similar Messages

  • Setting timeout for all the web test scripts in the solution

    Hello,
    I have around 16 web test scripts (using VSTS 2010 ultimate version) in my project (in a solution). By default the timeout set for each request is 60 sec. I need to increase the timeout to 180 sec. Currently, I am clicking on each request and modifying
    the timeout parameter from the Properties window.
    Is there any common setting for timeout available which would be acting across all the scripts?
    Thanks.

    Hello,
    We only can set Timeouts for a separate request in Visual Studio Web Test. There is no way to set Timeout for all requests in VS IDE. But you can write you own logic code using
    Timeout Property in a web test plugin to set Timeout for all requests in a web test.
    About how to write a web test plugin, please see:
    How to: Create a Web Performance Test Plug-In
    Best regards,
    Amanda Zhu <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    MSDN Community Support
    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

  • Set timeout for completion of each thread

    i have a requirement where i need to start n threads and set timeout for completion of each thread.
    if the thread is not executed successfully(because of timeout ) i have to enter in audit table that it failed because of timeout
    if executed successfully update audit table with success.
    can some one give me solution for this using ThreadPoolExecutor available jdk1.5

    Add a scheduled task to time out the task (when it would time out). Keep the Future and cancel it if the task completes successfully.
    final Future future = executor.schedule(new TimeoutTask(), timeoutMS, TimeUnit.MILLI_SECONDS);
    executor.execute(new Runnable() {
      public void run() {
          try {
             task.run();
          } finally {
             future.cancel(true);
    });

  • Set timeout for URL connection in java1.4

    hi
    I want to set timeout for URL connection in java 1.4..
    java 5.0 provides with a setTimeout(int ) method but how should it be done in 1.4 environment
    Thanks in advance
    sneha

    sun.net.client.defaultConnectTimeout (default: -1)
    sun.net.client.defaultReadTimeout (default: -1)
    See the [Networking Properties|http://java.sun.com/j2se/1.4.2/docs/guide/net/properties.html].

  • Setting timeout for webservice

    hello all,
    I have made client program to connect to a webservice using dynamic url, my problem is i am unable to set the timeout of the webservice if anybody knows please let me know. my code is as follows.
    WebServiceClient ann = testpackage.TestClassService.class.getAnnotation(WebServiceClient.class);
    try {
    testpackage.TestClassService service = new testpackage.TestClassService(new URL("MY URL"), new QName(ann.targetNamespace(), ann.name()));
    testpackage.TestClass port = service.getTestClassPort();
    String result = port.getUserTask("HELLO");
    System.out.println(result);
    } catch (MalformedURLException ex) {
    using this code how can i set timeout at client side
    thanks in advance

    hi there thanks for your reply but your solution didn't worked for me. may be because of mistake in my question explanation i will explain it again
    WebServiceClient ann = testpackage.TestClassService.class.getAnnotation(WebServiceClient.class);
    try {
    testpackage.TestClassService service = new testpackage.TestClassService(new URL("MY URL"), new QName(ann.targetNamespace(), ann.name()));
    testpackage.TestClass port = service.getTestClassPort();
    String result = port.getUserTask("HELLO");
    System.out.println(result);
    } catch (MalformedURLException ex) {
    using this code i am calling my webservice and the function "getUserTask" which give me some output in return.
    now, what situation i am facing is whenever i make a call to the above function and if RTO occurs after the call of the function then my application comes in to a hang mode situation. and i am unable to do anything untill the reconnection of the network occurs.Either i have to wait for the reconnection or i have to terminate my applicartion.
    My desire is, i should be able to set my timeout period of a web service request. if no reply comes in the given time period then i should be able to raise any message to the user.
    I think ihave made myself a bit more clear.
    thanks for your reply once again.

  • Setting timeout for SOAP requests in a webservice client

    I am trying to set the timeout for a synchronous SOAP request sent to a Web Service deployed on weblogic 8.1 SP2. I tried setting timeout thru bindinginfo setTimeout() and also javax.xml.rpc.Stub _setProperty(). Both of them seem to be not working. I set the value to as low as 1 sec but i still donot get a timeout. Other properties/method from these two classes work fine though (like endpointaddress property in javax.xml.rpc.Stub and setVerbose flag to true in BindingInfo).
    Can someone please help.
    Thanks in Advance
    srini

    Our application calls the webservice provided by another company over the internet using the ssl. We use the wsdl url of the webservice on the destination while creating the port. If the destination is not available statement which creates the port blocks for around 4 minutes.
    I think the first network call gets the wsdl from the remote server. Thus we encounter delays before getting the stub created. How can I timeout such a calls.
    try {
    port = (new ServiceName_Impl(remoteWsdlURL)).getServiceNameSoap();
    } catch (IOException e) {                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • Set timeout for dynamic web service call in wls

    Hi,
    I have a dynamic client using Call interface to invoke 3rd party web service. How can I set the timeout for the call? I know there is a property to set for static client.
    Thanks

    Have you checked out the stub properties:
    weblogic.wsee.transport.connection.timeout
    weblogic.wsee.transport.read.timeout
    http://edocs.beasys.com/wls/docs92/webserv/client.html#wp228628

  • Question on setting timeouts for leave approval

    Let us say there are three employees A is reporting to B, who inturn reports to C.
    If A applies for leave,then the notification goes to B.
    If B's position is vacant(undergoing recruitment) then the leave requests are lying under B's queue.
    Can they be forwarded to the next level (by setting timeouts).
    If yes, can please guide me with the navigation.

    hi,
    do you mean JTable or JTree. In any case, this might help:
    http://www2.gol.com/users/tame/swing/examples/SwingExamples.html
    greetz,
    stijn

  • Timeout for cfstoredproc

    Hi. Is there a way to set timeout for the tag
    <CFSTOREDPROC>? I mean, for cfquery, it has a parameter
    timeout in seconds. How about for CFSTOREDPROC?
    I tried using
    <cfset startproc = GetTickCount()>
    <cfsetting requesttimeout = "20" />
    <CFSTOREDPROC PROCEDURE="fsdfsd" DATASOURCE="sfsds">
    cfprorparams here.........
    </CFSTOREDPROC>
    <cfset proc_execute = GetTickCount() - startproc >
    proc_execute returns about 30,000 ms which is 30 s. But the
    timeout needs to end it in 20 s. It seems requesttimeout doesn't
    include the time it took for the stored procedure executing. That
    is why I'm looking for a timeout in cfstoredproc. Any suggestions?
    I don't wanna go to the Oracle server and set the timeout settings.
    I want it done in Coldfusion. Thanks.

    There is no timeout attribute for cfstoredproc. Since all the
    processing is occurring inside the database there is no way for us
    to time it out. Also, since we do not know the DBMS in advance we
    could not use any DBMS specific means. If Oracle SQL lets you set
    it inside the SP, that is your way to go.
    RequestTimeout/page timeouts only cover the time CF is in
    control of the thread.

  • Timeout for HR Saved For Later

    Hi
    Is there any way to set timeout for workflow item “Saved For Later”? It seems that we have numerous records with status “Open” under item type “HRSFL”. System is keeping records age more than 1 year.
    I’m looking for the correct way to remove these records if it exceed 90 days when staff did not proceed to update it.
    Thanks

    You must have registered some provider for your portlets. Go to adminstration screens of portal. Goto edit provider from there and increase the portlet timeout.
    Also change the time out value in your provider.xml for the corresponding JSPs.

  • Timeout for telnet

    Guys, I need to check if an application is running on hte servers. It's for close to 10,000 servers. The easiest way is to telnet to the application port and it responds with the version.
    That's easy, but some nasty servers do not timeout the telnet session and my script hangs. Any way to set a timeout for telnet?
    basically I run:
    telnet $host $port 2> /dev/null | grep ^pblocald > /dev/null
    One workaround is to use the Net::Telnet perl module which provides a timeout. Any other idea?
    Thanks
    Vladimir

    Hi,
    You can set timeout for telnet session ,First change the users primary shell as ksh (default bourne shell) and please set the same TMOUT environment variable in ksh .
    TMOUT If set to a value greater than zero, the shell will terminate if a command is not entered within the
    prescribed number of seconds after issuing the PS1
    prompt. (Note that the shell can be compiled with a
    maximum bound for this value which cannot be
    exceeded.)
    Please see man ksh for further clarifications .
    I have another suggestions to do timeout , you can write a shell/perl script which should check telnetd daemon and time ,then use kill -9 for that particular telnetd PID ,and the script can be scheduled in crontab.
    Hope this answer your query.
    Rgds,
    dhana_slash

  • Timeout for connect

    Hi there!
    I've got troubles how I can define a timeout for CreateConnect methods.
    I made a search, and found that OCCI itself doesn't support such timeout.
    I tried some parameters in sqlnet.ora
    such as: names.initial_retry_timeout, SQLNET.INBOUND_CONNECT_TIMEOUT and names.connect_timeout=3, but that didnt help at all.
    Does anybody know, how I can set timeout for database connect?
    Thanks,
    Amdras

    Hello Cipa,
    I have set this variable, but when connecting via sqlplus this process is using 100%CPU and I am not able to connect to database to start it.
    When starting sqlplus with strace it seems that there is loop in the poll function. Do you have any idea what the problem might be? Oracle version is 10.2.0.1.0
    Thanks for any help.
    Martin
    Trace:
    bind(7, {sa_family=AF_INET, sin_port=htons(0), sin_addr=inet_addr("127.0.0.1")}, 16) = 0
    getsockname(7, {sa_family=AF_INET, sin_port=htons(32918), sin_addr=inet_addr("127.0.0.1")}, [46909632806928]) = 0
    getpeername(7, 0x7fffffb9bd5c, [46909632806928]) = -1 ENOTCONN (Transport endpoint is not connected)
    getsockopt(7, SOL_SOCKET, SO_SNDBUF, [-6148700272152420352], [4]) = 0
    getsockopt(7, SOL_SOCKET, SO_RCVBUF, [-6148700272152420352], [4]) = 0
    fcntl(7, F_SETFD, FD_CLOEXEC)           = 0
    fcntl(7, F_SETFL, O_RDONLY|O_NONBLOCK)  = 0
    pipe([8, 9])                            = 0
    pipe([10, 11])                          = 0
    clone(child_stack=0, flags=CLONE_CHILD_CLEARTID|CLONE_CHILD_SETTID|SIGCHLD, child_tidptr=0x2aaaaccacf30) = 15442
    --- SIGCHLD (Child exited) @ 0 (0) ---
    rt_sigprocmask(SIG_BLOCK, [PIPE], NULL, 8) = 0
    rt_sigaction(SIGPIPE, {0x2aaaabb3c838, ~[ILL ABRT BUS FPE SEGV USR2 XCPU XFSZ SYS RTMIN RT_1], SA_RESTORER|SA_RESTART|SA_SIGINFO, 0x2aaaac851bd0}, {SIG_DFL}, 8) = 0
    rt_sigprocmask(SIG_UNBLOCK, [PIPE], NULL, 8) = 0
    wait4(15442, [{WIFEXITED(s) && WEXITSTATUS(s) == 0}], 0, NULL) = 15442
    close(8)                                = 0
    close(11)                               = 0
    poll([{fd=7, events=POLLIN|POLLRDNORM}, {fd=7, events=0}, {fd=10, events=POLLOUT}], 3, 0) = 0
    poll([{fd=7, events=POLLIN|POLLRDNORM}, {fd=7, events=0}, {fd=10, events=POLLOUT}], 3, 0) = 0
    poll([{fd=7, events=POLLIN|POLLRDNORM}, {fd=7, events=0}, {fd=10, events=POLLOUT}], 3, 0) = 0
    poll([{fd=7, events=POLLIN|POLLRDNORM}, {fd=7, events=0}, {fd=10, events=POLLOUT}], 3, 0) = 0
    poll([{fd=7, events=POLLIN|POLLRDNORM}, {fd=7, events=0}, {fd=10, events=POLLOUT}], 3, 0) = 0
    poll([{fd=7, events=POLLIN|POLLRDNORM}, {fd=7, events=0}, {fd=10, events=POLLOUT}], 3, 0) = 0
    poll([{fd=7, events=POLLIN|POLLRDNORM}, {fd=7, events=0}, {fd=10, events=POLLOUT}], 3, 0) = 0
    poll([{fd=7, events=POLLIN|POLLRDNORM}, {fd=7, events=0}, {fd=10, events=POLLOUT}], 3, 0) = 0
    poll([{fd=7, events=POLLIN|POLLRDNORM}, {fd=7, events=0}, {fd=10, events=POLLOUT}], 3, 0) = 0
    poll([{fd=7, events=POLLIN|POLLRDNORM}, {fd=7, events=0}, {fd=10, events=POLLOUT}], 3, 0) = 0
    poll([{fd=7, events=POLLIN|POLLRDNORM}, {fd=7, events=0}, {fd=10, events=POLLOUT}], 3, 0) = 0
    poll([{fd=7, events=POLLIN|POLLRDNORM}, {fd=7, events=0}, {fd=10, events=POLLOUT}], 3, 0) = 0Edited by: martin_m on Aug 28, 2008 1:42 AM

  • Regarding setting timeout

    Hi all,
    I have a requirement to set timeout for executing weservice using
    WebDynpro (Webservice model ).. Iam able to do this for
    Adaptive Webservice model, but my need is for Webservice model only..
    Can anybody help me regarding this,
    Thanks in Advance
    LakshmiNarayana.N

    Hi Lakshmi,
    You can Refer to Piyush's reply in this [thread|SocketTimeout Exception while calling a Web Service from EJB;.
    This variable sets the default timeout for all the Web Service Clients on the Server.
    Hope it helps.
    Regards,
    Alka.

  • Hi I have two questions. I am using NAS 4.1 and was wondering is it possible to set a different session timeout for different users? How is the session timeout set? Thanks, YS

     

    <i>I am using NAS 4.1 and was wondering is it possible to set a different session timeout for different users?</i>
    Um, there is no such thing as NAS4.1.
    I'm assuming that you mean NAS4.0 (maybe NAS4.0sp1?). If so, then the session timeouts are specified in the session section of the NTV configuration files.
    AFAIK, you can specify session timeouts on a per user basis.

  • Set a timeout for "read from text file"

    I Need to read from a text file on a remote pc and use the read from text file function to do this. It wotks but sometimes this pc is down causing long wait times in my vi.
    Is there a way to set a timeout for the read from text file function, or is there an other solution?
    Thank you

    You could check that the path is valid first before you attempt to read the file.  hen put the file read in a True-False case structure based on the results of the check.  You can use the function "Check if File or Folder Exists"  It checks whether a file or folder exists on disk at a specified path. This VI works with standard files and folders as well as files in LLB files.   The function is found in the File I/O --> Advanced File Functions palette.
    Tom

Maybe you are looking for