Return-Path: X-Original-To: apmail-tomcat-users-archive@www.apache.org Delivered-To: apmail-tomcat-users-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 47E647ABC for ; Fri, 23 Dec 2011 22:04:30 +0000 (UTC) Received: (qmail 61140 invoked by uid 500); 23 Dec 2011 22:04:25 -0000 Delivered-To: apmail-tomcat-users-archive@tomcat.apache.org Received: (qmail 61059 invoked by uid 500); 23 Dec 2011 22:04:25 -0000 Mailing-List: contact users-help@tomcat.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "Tomcat Users List" Delivered-To: mailing list users@tomcat.apache.org Received: (qmail 61017 invoked by uid 99); 23 Dec 2011 22:04:25 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 23 Dec 2011 22:04:25 +0000 X-ASF-Spam-Status: No, hits=0.7 required=5.0 tests=SPF_NEUTRAL X-Spam-Check-By: apache.org Received-SPF: neutral (nike.apache.org: local policy) Received: from [76.96.62.24] (HELO qmta01.westchester.pa.mail.comcast.net) (76.96.62.24) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 23 Dec 2011 22:04:17 +0000 Received: from omta11.westchester.pa.mail.comcast.net ([76.96.62.36]) by qmta01.westchester.pa.mail.comcast.net with comcast id Cm091i0020mv7h051m3wba; Fri, 23 Dec 2011 22:03:56 +0000 Received: from new-host-2.home ([108.48.85.44]) by omta11.westchester.pa.mail.comcast.net with comcast id Cm3n1i0020xPRh03Xm3q8h; Fri, 23 Dec 2011 22:03:54 +0000 Message-ID: <4EF4FAC6.6090207@christopherschultz.net> Date: Fri, 23 Dec 2011 17:03:50 -0500 From: Christopher Schultz User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:9.0) Gecko/20111220 Thunderbird/9.0 MIME-Version: 1.0 To: Tomcat Users List Subject: Re: Running not multithreaded application References: <4EE92E9D.3010606@christopherschultz.net> <4EEA115E.2060201@christopherschultz.net> <4EEA4F29.7050203@christopherschultz.net> <4EF49779.9070005@christopherschultz.net> In-Reply-To: X-Enigmail-Version: 1.3.4 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Virus-Checked: Checked by ClamAV on apache.org -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 HernĂ¡n, On 12/23/11 4:24 PM, hernan wrote: > Process p = Runtime.getRuntime().exec(...); > > // Sending input to process p OutputStream os = > p.getOutputStream(); BufferedWriter bw = new BufferedWriter(new > OutputStreamWriter(os)); [...] // send input through bw > bw.close(); os.close(); > > // Receiving output from process p InputStream is = > p.getInputStream(); BufferedReader br = new BufferedReader(new > InputStreamReader(is)); [...] // receiving output through br > br.close(); is.close(); > > I will add the stderr to this code. If you just add similar stderr code after your stdout handling code, you may still suffer a deadlock: if the stderr buffer fills up, the child process will block waiting for you to read it, and output to stdout will stall as well. I think the commons folks have a component to handle all of this stuff for you in a tidy package. > My next step is write a Scheduler class, may be a "singleton" or > something similar to work as a resource-limiter, also I will need > other rules related to users and sessions. Actually, when the > threshold is reached, the Scheduler should queue the "job". For the > moment I will think that the queue capacity is infinite :). > > I wonder which alternatives do I have to implement my Scheduler > class in tomcat. In fact, I've to read a lot about tomcat, so I've > started reading the apache tomcat 7 (Vukotic and Goodwill) to > understand how tomcat works exactly. I'm not sure that you need anything Tomcat-specific for this. Just something that will work in any servlet container should be sufficient. If you just want to limit resources and give anyone who exceeds the limit a "sorry, try again" message, it shouldn't be too difficult to implement with an atomic counter. If you want to implement queuing, then you'll probably also want the clients to continue to issue "update" requests to find out if their job was completed. That will certainly be more complicated, but probably more robust. You'll want to look at Java's "executors" for that: you can queue a job and get a "Future" object that you can poll for completeness. Stick that object in the session after queuing the job and use something like META REFRESH or Ajax calls to periodically check the status of the job. If the user logs out, you might want to mark the job as cancelled just so you don't waste your time. I would also *not* allow an infinite queue length. There are of course lots of other ways to do this kind of thing. - -chris -----BEGIN PGP SIGNATURE----- Version: GnuPG/MacGPG2 v2.0.17 (Darwin) Comment: GPGTools - http://gpgtools.org Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ iEYEARECAAYFAk70+sYACgkQ9CaO5/Lv0PC5HgCfeTdI8bVDgMXuln0HW2tdnuxo qFYAniTf6OSaeES8Fi69yJBfbcpRGJNW =KSqB -----END PGP SIGNATURE----- --------------------------------------------------------------------- To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org For additional commands, e-mail: users-help@tomcat.apache.org