On Fri, Dec 23, 2011 at 12:00 PM, Christopher Schultz < ch...@christopherschultz.net> wrote:
> -----BEGIN PGP SIGNED MESSAGE----- > Hash: SHA1 > > Hernan, > > On 12/22/11 9:47 PM, hernan wrote: > > Finally, I'm just using Runtime.exec() to execute a c++ program > > that uses glpk, and using stdin/stdout to communicate them. The > > whole system is running tomcat, axis2, java and c/c++. > > Just be very careful about thread and stream management when using > Runtime.exec(): you must consume everything from both stdout *and* > stderr, otherwise you can lock-up the thread and bring down your > server. You might want to have a resource-limiter on the number of > concurrent calls to GLPK processes just to make sure there are always > some threads available for other things like monitoring (including > reporting the number of GLPK processes that are running). > Yes, I agree. The I send all the input to the process and close the channel, then the process read all the input and start the processing phase when all the input is received. Actually it does not work like a traditional pipe but this solution works for me. 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. 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. http://www.amazon.com/Apache-Tomcat-7-Aleksa-Vukotic/dp/1430237236/ref=sr_1_cc_1?s=gift-cards&ie=UTF8&qid=1324673900&sr=1-1-catcorr If you have some other lecture for suggest me, it will be appreciated. > > I don't know about the demand for linear-physics-via-HTTP, it's > > only about a service for inventory and order management. > > I think I'm lost. What are you using GLPK for, then? There are many logistics decisions that companies have to execute his everyday operations about procurement, inventory, distribution and sales. For example, if a company has a depot that receives a lot of orders from point of sales, and they have to ship products from a depot to customers using trucks, they have to choose which product (for a customer) put in each truck and in which order each truck visits each customer. In general there are capacity constraints (due to physical limitations of the trucks -i.e. weight, size, ...) and organizations want to optimize some metric(s) (for example, mean delivery time, fuel consumption, etc.). There is a lot of literature about this kind of problems, if you're interested may be you can start in: http://en.wikipedia.org/wiki/Vehicle_routing_problem Using glpk you can model this kind of problems and find solutions using the glpk or rewrite some routines to write your own algorithm to find solutions. Regards, HernĂ¡n