comp.lang.java.programmer http://groups-beta.google.com/group/comp.lang.java.programmer [EMAIL PROTECTED]
Today's topics: * Vector takes a lot memory - 3 messages, 3 authors http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/f00ea165043778e1 * Error trying to set up JNDIand Oracle database - 1 messages, 1 author http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/edce8724ca83eefa * Array referencing - 3 messages, 3 authors http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/1e5bd96d75c26308 * Sending mail - Created By field contains junk information - 1 messages, 1 author http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/f36d7268525953f7 * Tomcat, Apache and Application in / context path - 2 messages, 2 authors http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/c5b39f1a1691dde * create stand alone application - 2 messages, 2 authors http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/aa0f7e4767471263 * How to use Version Property in Hibernate or Nhibernate - 2 messages, 2 authors http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/f81a50a492031d2d * any easy way to write out a XML DOM object to file? - 1 messages, 1 author http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/5f6b296065e077c6 * How to use Transactions in stateless session bean? - 1 messages, 1 author http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/ee73b722c1d5e795 * output PDF in IE KO with Apache - 1 messages, 1 author http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/fd1a726040d253bb * Is this a bad restart() idea? - 2 messages, 2 authors http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/4e2648af56dce013 * Problem with Runtime execute - 1 messages, 1 author http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/768801f620e9527c * Correct Semaphore Implementation in Java - 2 messages, 1 author http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/8259aec1ceed4f8f * Servlet OutOfMemory on images. Please help me! - 1 messages, 1 author http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/2b54ac9443545bf3 * JSP Workflow FlowControl PageFlow Engine - 1 messages, 1 author http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/acd037da0d51e674 * time factor for loops and arrays - 1 messages, 1 author http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/165f1800f74e0914 ============================================================================== TOPIC: Vector takes a lot memory http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/f00ea165043778e1 ============================================================================== == 1 of 3 == Date: Thurs, Nov 25 2004 8:21 am From: [EMAIL PROTECTED] (homecurr) Here is my code. The String take about 20000 * 30 * 8 = 5M. But once I put them in the Vector, it takes about 100M memory. Why? How can I fix it? Another good data structure than Vector? Thanks, qq public static void main(String[] args) { Vector data = new VTest().load(); int i = 1; } public Vector load(){ int row = 20000; int col = 30; Vector data = new Vector(100, 100); for (int i = 0; i < row; i++){ String[] line = new String[col]; for (int j = 0; j < col; j++){ line[j] = " " + (int)(Math.random() * 100000000); } data.add(line); } return data; } == 2 of 3 == Date: Thurs, Nov 25 2004 5:44 pm From: Michael Borgwardt homecurr wrote: > Here is my code. > > The String take about 20000 * 30 * 8 = 5M. Nope. Each of your 20000*30 Strings takes about 56 bytes, not 8, since Ja va uses unicode and there is an overhead for each object - twice, because String encapsulates a char[] array, the length field of the array and probably some additiona l overhead. That alone makes for 32M. Then there are 20000 String arrays of length 30 , which need about 136 bytes for the array overhead and 30 references - another 2.6M. If you don't believe my numbers, read this: http://www.javaworld.com/javaworld/javatips/jw-javatip130.html > But once I put them in the > Vector, it takes about 100M memory. The vector itself should add only about 100k overhead. What exactly "take s about 100M memory"? The JVM process? That contains a lot more than just your vector, and always keeps a lot of empty space ready if possible. > Why? How can I fix it? How about not saving numbers as Strings? That's your biggest waste of spa ce by far. > Another good data structure than Vector? Your problem is not with Vector, though it shouldnÄt be used anymore (i nstead, ArrayList). == 3 of 3 == Date: Thurs, Nov 25 2004 5:22 pm From: Andrew Thompson On 25 Nov 2004 08:21:33 -0800, homecurr wrote: > public Vector load(){ > int row = 20000; > int col = 30; > Vector data = new Vector(100, 100); > for (int i = 0; i < row; i++){ If it is always a specific size, I would recommend using an array rather than a vector. This will allow you to store primitve types rather than String objects. > String[] line = new String[col]; > for (int j = 0; j < col; j++){ > line[j] = " " + (int)(Math.random() * > 100000000); What is the point of the " "? It would be much more efficient to keep this as 'int' inside the array (OK, assuming you toss the vector, a multi-dinensional array) > } > > data.add(line); > } > return data; > } HTH -- Andrew Thompson http://www.PhySci.org/codes/ Web & IT Help http://www.PhySci.org/ Open-source software suite http://www.1point1C.org/ Science & Technology http://www.LensEscapes.com/ Images that escape the mundane ============================================================================== TOPIC: Error trying to set up JNDIand Oracle database http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/edce8724ca83eefa ============================================================================== == 1 of 1 == Date: Thurs, Nov 25 2004 8:26 am From: [EMAIL PROTECTED] (lydie) Hi, I am trying to set up a very simple application accessing to my Oracle database using Tomcat in order to let him deal with connection pooling. So I tried to do what what explained in the documents I found but it seems that I have done something wrong. I have added the following code in the server.xml (the tomcat one in the conf directory) <Context path="/BaseDeDonnees" reloadable="true" docBase="C:\Dev\eclipse\workspace\BaseDeDonnees" workDir="C:\Dev\eclipse\workspace\BaseDeDonnees\work" > <Logger className="org.apache.catalina.logger.SystemOutLogger" verbosity="4" timestamp="true"/> <!-- Test pour faire gerer les connexions Oracle par Tomcat --> <Resource name="jdbc/BaseDeDonnees" scope="Shareable" type="javax.sql.DataSource"/> <ResourceParams name="jdbc/BaseDeDonnees"> <parameter> <name>factory</name> <value>org.apache.commons.dbcp.BasicDataSourceFactory</value> </parameter> <parameter> <name>maxWait</name> <value>5000</value> </parameter> <parameter> <name>maxIdle</name> <value>10</value> </parameter> <parameter> <name>driverClassName</name> <value>oracle.jdbc.driver.OracleDriver</value> </parameter> <parameter> <name>url</name> <value>jdbc:oracle:thin:@toto:1521:symp</value> </parameter> <parameter> <name>username</name> <value>myuser</value> </parameter> <parameter> <name>password</name> <value>mypassword</value> </parameter> <parameter> <name>validationQuery</name> <value>select 1</value> </parameter> <parameter> <name>testOnBorrow</name> <value>true</value> </parameter> <parameter> <name>removeAbandoned</name> <value>true</value> </parameter> <parameter> <name>removeAbandonedTimeout</name> <value>120</value> </parameter> </ResourceParams> </Context> then I created a web.xml for my application (so in the WEF-INF directory of my application) that looks like this: <!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd"> <web-app> <resource-ref> <description>Oracle Datasource</description> <res-ref-name>jdbc/BaseDeDonnees</res-ref-name> <res-type>javax.sql.DataSource</res-type> <res-auth>Container</res-auth> </resource-ref> </web-app> and finally I created a very simple servlet that only does this: System.out.println("post"); HttpSession session = request.getSession(); try { Context initContext = new InitialContext(); Context envContext = (Context)initContext.lookup("java:/comp/env"); DataSource ds = (DataSource) envContext.lookup("jdbc/BaseDeDonnees"); Connection conn = ds.getConnection(); session.setAttribute("message","ok"); response.sendRedirect("../reponse.jsp"); } catch (NamingException e) { session.setAttribute("message","pb naming exception"); response.sendRedirect("../reponse.jsp"); e.printStackTrace(); } catch (SQLException e) { session.setAttribute("message","pb sql exception"); response.sendRedirect("../reponse.jsp"); e.printStackTrace(); } It seems to work fine until I try to get a connection: I have the following error: java.lang.NoClassDefFoundError: org/apache/commons/collections/CursorableLinkedList org.apache.commons.pool.impl.GenericObjectPool.(GenericObjectPool.java:392) org.apache.commons.pool.impl.GenericObjectPool.(GenericObjectPool.java:266) org.apache.commons.dbcp.AbandonedObjectPool.(AbandonedObjectPool.java:96) org.apache.commons.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:762) org.apache.commons.dbcp.BasicDataSource.getConnection(BasicDataSource.java:518) fr.tomcat.IdentificationServlet.doPost(IdentificationServlet.java:36) javax.servlet.http.HttpServlet.service(HttpServlet.java:763) javax.servlet.http.HttpServlet.service(HttpServlet.java:856) org.apache.catalina.servlets.InvokerServlet.serveRequest(InvokerServlet.java:466) org.apache.catalina.servlets.InvokerServlet.doPost(InvokerServlet.java:216) javax.servlet.http.HttpServlet.service(HttpServlet.java:763) javax.servlet.http.HttpServlet.service(HttpServlet.java:856) If anyone can help or tell me where I can find other documents (except the Tomcat site I have already visited) Thanks a lot for your help Lydie ============================================================================== TOPIC: Array referencing http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/1e5bd96d75c26308 ============================================================================== == 1 of 3 == Date: Thurs, Nov 25 2004 8:26 am From: [EMAIL PROTECTED] ([EMAIL PROTECTED]) Hi, Here is my routine. It is not working. Anyone see the problem? public void test () { String[][] data_1 = { { "AA_1", "Hello world" }, { "AA_2", "123456789" } }; String[][] data_2 = { { "BB_1", "Bla Bla" }, { "BB_1", "222222222" }, }; String[][] data_3 = { { "CC_1", "Happy New Year" }, { "CC_1", "333333333" }, }; for(int i=1; i <=3; i++){ // following line is wrong. Anyone know how to do it?? String data_name[][] = "data_"+i; System_out_println(" first = "+data_name[j][0]; System_out_println(" second = "+data_name[j][1]; } } Thank you! Anders == 2 of 3 == Date: Thurs, Nov 25 2004 5:47 pm From: Michael Borgwardt [EMAIL PROTECTED] wrote: > // following line is wrong. Anyone know how to do it?? > String data_name[][] = "data_"+i; What is it *supposed* to do? You're trying to assing a String to a reference of type String[][], which is obviously not possible. == 3 of 3 == Date: Thurs, Nov 25 2004 8:39 pm From: "Andrei Kouznetsov" > Here is my routine. It is not working. Anyone see the problem? > > public void test () > { > > String[][] data_1 = { > { "AA_1", "Hello world" }, > { "AA_2", "123456789" } > }; > String[][] data_2 = { > { "BB_1", "Bla Bla" }, > { "BB_1", "222222222" }, > }; > String[][] data_3 = { > { "CC_1", "Happy New Year" }, > { "CC_1", "333333333" }, > }; > > for(int i=1; i <=3; i++){ > // following line is wrong. Anyone know how to do it?? > String data_name[][] = "data_"+i; > System_out_println(" first = "+data_name[j][0]; > System_out_println(" second = "+data_name[j][1]; > } > } > I suppose you are from VisualBasic world... What you can do is following: Object [] data = new Object[3]; data[0] = data_1; data[1] = data_2; data[2] = data_3; for(int i=0; i < 3; i++){ String data_name[][] = (String[][]) data[i]; System_out_println(" first = "+data_name[j][0]; System_out_println(" second = "+data_name[j][1]; } -- Andrei Kouznetsov http://uio.dev.java.net Unified I/O for Java http://reader.imagero.com Java image reader http://jgui.imagero.com Java GUI components and utilities ============================================================================== TOPIC: Sending mail - Created By field contains junk information http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/f36d7268525953f7 ============================================================================== == 1 of 1 == Date: Thurs, Nov 25 2004 11:22 am From: GaryM "Jack Andersson" <[EMAIL PROTECTED]> wrote in news:[EMAIL PROTECTED]: > Why is this? Is it a matter of configuration on the mail server? > Or do I have to set some kind of property before sending mail? > It looks like it might be the mail server. Do you have an alternative SMTP server to test it on? Also trying putting Javamail in debug mode and watch what it sends to the server. It should show the reply-to being written, so you can see if it is going in clean. ============================================================================== TOPIC: Tomcat, Apache and Application in / context path http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/c5b39f1a1691dde ============================================================================== == 1 of 2 == Date: Thurs, Nov 25 2004 8:44 am From: [EMAIL PROTECTED] (Joshua) I have Apache configured with Tomcat using mod_jk2. For example: Apache runs on port 80 Tomcat runs on port 8080 I can access Tomcat resources by connecting to port 80 through apache. I have deployed a war file using the Tomcat Web Application Manager. This by default uses the name of the war file as its context path. What I want is to deploy an application in Tomcat so that when I access http://<address> on the default port 80 the webapp is served instead of http://<address>/<context path>/. I have searched this newsgroup but unfortunately haven't found anything of help. == 2 of 2 == Date: Thurs, Nov 25 2004 6:33 pm From: Juha Laiho [EMAIL PROTECTED] (Joshua) said: >I have Apache configured with Tomcat using mod_jk2. For example: > >Apache runs on port 80 >Tomcat runs on port 8080 > >I can access Tomcat resources by connecting to port 80 through apache. > >I have deployed a war file using the Tomcat Web Application Manager. >This by default uses the name of the war file as its context path. > >What I want is to deploy an application in Tomcat so that when I >access http://<address> on the default port 80 the webapp is served >instead of http://<address>/<context path>/. Two choices; 1. - you could set up Apache so that requests to anything (except starting with /<context path>/ are redirected either internally or externally to resources within /<context path>/ 2. - deploy your webapp so that it takes over the Tomcat root context (might need manual creation of context XML file) - configure mod_jk2 to take over the Apache root "directory" (have done this with mod_jk, but the configuration for mod_jk2 is wildly different) -- Wolf a.k.a. Juha Laiho Espoo, Finland (GC 3.0) GIT d- s+: a C++ ULSH++++$ P++@ L+++ E- W+$@ N++ !K w !O !M V PS(+) PE Y+ PGP(+) t- 5 !X R !tv b+ !DI D G e+ h---- r+++ y++++ "...cancel my subscription to the resurrection!" (Jim Morrison) ============================================================================== TOPIC: create stand alone application http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/aa0f7e4767471263 ============================================================================== == 1 of 2 == Date: Thurs, Nov 25 2004 8:48 am From: Steve Sobol Andrew Thompson wrote: > On Wed, 24 Nov 2004 20:51:53 -0800, Steve Sobol wrote: > > >>Andrew Thompson wrote: >> >>>On Wed, 24 Nov 2004 23:53:24 +0200, tomer wrote: >>> >>> >>>>maybe I will need a installation program.....(can i do it)? >>> >>><http://www.physci.org/codes/javafaq.jsp#jws> > > > a) > > >>that's one way, using an install builder or JAR to EXE utility is another, > > > b) That is not a good solution generally.. > <http://www.physci.org/codes/javafaq.jsp#exe> OK, let me clarify: I don't mean a native-code compiler like Jet or Excelsior's product, I mean a product like ej technologies' exe4j that uses an EXE wrapper and leaves the java code in a JAR (or in multiple JARs). -- JustThe.net Internet & New Media Services, http://JustThe.net/ Steven J. Sobol, Geek In Charge / 888.480.4NET (4638) / [EMAIL PROTECTED] PGP Key available from your friendly local key server (0xE3AE35ED) Apple Valley, California Nothing scares me anymore. I have three kids. == 2 of 2 == Date: Thurs, Nov 25 2004 7:47 pm From: "Andy Flowers" Andrew Thompson wrote: > On Wed, 24 Nov 2004 20:51:53 -0800, Steve Sobol wrote: > >> Andrew Thompson wrote: >>> On Wed, 24 Nov 2004 23:53:24 +0200, tomer wrote: >>> >>>> maybe I will need a installation program.....(can i do it)? >>> >>> <http://www.physci.org/codes/javafaq.jsp#jws> > > a) > There's a wrinkle with Java WebStart however. The corporate world. If the OP is trying to target these then they are more likely to accept a pre-packaged desktop solution that they can test, or a web application. There area lot of large corporations out there (and probably countless other companies of various sizes) that do not like to have any applications downloaded onto their carefully tested, standard PC images, no matter how it is sold to them. They will allow pre web applications or desktop applications that go through weeks/months of testing to ensure they won't break anything. I work for one of these and they try hard to prevent web start applications [and ActiveX for that matter] along with as many applets as they can get away with via a very hefty, and overly restrictive, security policy. Personally I believe Java Web Start is an excellent technology but I'm a technologist NOT corporate risk management, but given enough time all the scares from badly secured applets and the more problematic ActiveX will hopefully begin to fade and we can start to see more use of this technology. BTW, Microsoft now has very similar technology with .NET, wonder where they got the idea for that from :). ============================================================================== TOPIC: How to use Version Property in Hibernate or Nhibernate http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/f81a50a492031d2d ============================================================================== == 1 of 2 == Date: Thurs, Nov 25 2004 8:54 am From: [EMAIL PROTECTED] (orientphoebus) I have a table with columns like this: ---------------------------------------------- Id number not null, Name VARCHAR2(100) not null, Update_DT DateTime not null ---------------------------------------------- The Update_DT is used, so that the table can keep all the history versions of the data. I want to use Hibernate to get data from this table by a simple Session.Load(), but I'd like to get the latest version always. In the hbm.xml, I notice there are <version> and <vimestamp> properties, which have the similar meaning. How can I use Session.Load() to load the latest record into Object? Any similar simple solution will help. Thanks == 2 of 2 == Date: Thurs, Nov 25 2004 6:07 pm From: Michael Borgwardt orientphoebus wrote: > I have a table with columns like this: > ---------------------------------------------- > Id number not null, > Name VARCHAR2(100) not null, > Update_DT DateTime not null > ---------------------------------------------- > The Update_DT is used, so that the table can keep all the history > versions of the data. > > I want to use Hibernate to get data from this table by a simple > Session.Load(), but I'd like to get the latest version always. > > In the hbm.xml, I notice there are <version> and <vimestamp> > properties, which have the similar meaning. No, they have a completely different meaning. There are no different versions of one data item in the DB. They only allow you to spot concurrent updates while not requiring transactions to span user interaction. > How can I use Session.Load() to load the latest record into Object? You'll have to do a query that asks for the row with the maximal timestamp. ============================================================================== TOPIC: any easy way to write out a XML DOM object to file? http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/5f6b296065e077c6 ============================================================================== == 1 of 1 == Date: Thurs, Nov 25 2004 5:21 pm From: Alex Kizub > > Now, I want to get the updated xml file from "doc", what to do? > Anything like doc.writeAsXMLFile("newFile.xml")? > OutputFormat format = new OutputFormat(doc); Writer writer = new FileWriter("newFile.xml"); XMLSerializer ser = new XMLSerializer(writer, format); ser.serialize(doc); writer.close(); Alex Kizub. ============================================================================== TOPIC: How to use Transactions in stateless session bean? http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/ee73b722c1d5e795 ============================================================================== == 1 of 1 == Date: Thurs, Nov 25 2004 5:55 pm From: "harry" Totally confused! read article saying how easy it is using the SessionSynx.... interface - ah can't coz only allowed in stateful beans! So failing to find anything convincing on the web I'm not sure what to do now? I have a stateless session bean (EJB1 - acting as a session facade) that calls methods on another stateless session bean (EJB2). I want to encapsulate several EJB2 method calls within a single EJB1 method. This method does some validation which might result in an exception being thrown so obviously I'll need to rollback somehow Do I have to create another session bean, this time make it stateful & put all methods that require transactions in there? or can I still achieve this using a stateless bean? Many thanks - appologies if not correct wording but a bit new to this! ============================================================================== TOPIC: output PDF in IE KO with Apache http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/fd1a726040d253bb ============================================================================== == 1 of 1 == Date: Thurs, Nov 25 2004 7:29 pm From: "Christophe Puaud" Hello, my webapp output a pdf. With Tomcat 4.1.29 it's OK for IE6 and Mozilla. With Tomcat 4.1.29 and Apache 2.0.49 it's OK for Mozilla but not for IE : The file doesn't start with %PDF The code of my JSP : response.reset(); response.setContentType("application/pdf"); response.setContentLength(pdfBytes.length); response.setHeader("content-disposition", "inline;filename=Rapport.pdf"); ServletOutputStream ouputStream = response.getOutputStream(); ouputStream.write(pdfBytes, 0, pdfBytes.length); ouputStream.flush(); ouputStream.close(); Thanks Christophe ============================================================================== TOPIC: Is this a bad restart() idea? http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/4e2648af56dce013 ============================================================================== == 1 of 2 == Date: Thurs, Nov 25 2004 7:05 pm From: DeMarcus Chris Smith wrote: > DeMarcus <[EMAIL PROTECTED]> wrote: > >>static void restart() >>{ >> _mainFrame.setVisual( false ); >> _mainFrame.dispose(); >> MySoftware.main( new String[0] ); >>} >> >> >>Now I can can call restart() from anywhere in the software and >>have a restart. >> >>The question is; is this bad programming? > > > Yes, it's a really bad idea. Just the problems that first come to mind > are: > > 1. This fails to terminate any previous threads, which means you have to > avoid multithreading like the plague (bad) or risk random modifications > of shared state that you don't want (very bad). > > 2. You've failed to reset any static variable to their initial values, > which could randomly break your code. > > 3. Your existing code may continue to run after the method returns. If > nothing else, you should at least find a way to safely terminate the > current thread at the end of that method. > But still. The user can always terminate the software by pressing the close-window-button up in the right corner (Windows). How can I simulate such event to my favor? And then after that do a restart of the software. Shouldn't that be kind of safe? /Daniel == 2 of 2 == Date: Thurs, Nov 25 2004 12:28 pm From: Chris Smith DeMarcus <[EMAIL PROTECTED]> wrote: > But still. The user can always terminate the software by pressing the > close-window-button up in the right corner (Windows). How can I > simulate such event to my favor? Whether the user can terminate the software that way depends on what you do in response to the resulting event. You can terminate the current process, though, with System.exit. > And then after that do a restart of > the software. If you need to restart your software, do it in a different process using Runtime.exec. Unfortunately, there isn't a portable way to accomplish this. > Shouldn't that be kind of safe? I don't understand what you mean. The code you posted is definitely NOT safe. -- www.designacourse.com The Easiest Way To Train Anyone... Anywhere. Chris Smith - Lead Software Developer/Technical Trainer MindIQ Corporation ============================================================================== TOPIC: Problem with Runtime execute http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/768801f620e9527c ============================================================================== == 1 of 1 == Date: Thurs, Nov 25 2004 11:13 am From: [EMAIL PROTECTED] (Fran Garcia) I will reply to myself. I have put the next code and it works fin try { Process p = Runtime.getRuntime().exec( "lame -b 8 -f -m j GRABANDO_DE_WEB.WAV nompractica.wav.mp3"); p.getOutputStream().close(); p.getInputStream().close(); p.getErrorStream().close(); p.waitFor(); }catch(Exception ex){ ex.printStackTrace();} I hope that somebody can use this code. Ciao ============================================================================== TOPIC: Correct Semaphore Implementation in Java http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/8259aec1ceed4f8f ============================================================================== == 1 of 2 == Date: Thurs, Nov 25 2004 11:48 am From: [EMAIL PROTECTED] (Frank Gerlach) Andrea Desole <[EMAIL PROTECTED]> wrote in message news:<[EMAIL PROTECTED]>... > I wouldn't say it's correct. There are two things that don't convince me: > 1) a thread shouldn't be able to call V without calling P. You can't > release a resource if you don't get it That is right. There is nothing in my implementation preventing abuse. There should always be something like a P() .. V() brace in the using code. > 2) notify is not deterministic. It would be better to have a FIFO queue, > or there is a chance, altough small, that a thread will wait forever Remote possibility > I also know that some JVMs don't work as they should, and in some cases > a waiting thread can wake up without notify being called. Hmm. Can you elaborate on this ? == 2 of 2 == Date: Thurs, Nov 25 2004 12:06 pm From: [EMAIL PROTECTED] (Frank Gerlach) "Matt Humphrey" <[EMAIL PROTECTED]> wrote in message news:<[EMAIL PROTECTED]>... > "Frank Gerlach" <[EMAIL PROTECTED]> wrote in message > news:[EMAIL PROTECTED] > > There seem to be quite a number of not very clean and simple > > implementations > > of java Semaphores in the internet. The following example is extremely > > simple (the Java 1.5 implementation is overfeatured IMHO) and correct: > > > > /** Semaphore class for managing limited resources (such as database > > * connections) > > * Author: Frank Gerlach ([EMAIL PROTECTED]) > > * Copyright: None. Use in any way you want. > > * located at: http://www.geocities.com/gerlachfrank/Semaphore.java > > */ > > public class Semaphore{ > > int count; > > /** Create the semaphore > > * @param initialcount number of resource items to manage > > */ > > public Semaphore(int initialcount){ > > count=initialcount; > > } > > > > /** Acquire one resource item > > */ > > public void P(){ > > synchronized(this){ > > if(count==0){ > > try{ > > wait(); > > }catch(InterruptedException ie){ > > //this should never happen > > System.err.println("caught InterruptedException in > > wait()"); > > } > > I havn't worked with this for a while, but shouldn't it be > while (count == 0) { > > because otherwise the arrival of a spurrious notify will cause the semaphore > to be granted when it is not yet ready. Alternatively (or in addition), > shouldn't the monitor be a private instance object and not "this" for > exactly the same reason? The while() loop is NOT necessary. Actually, the notify() can only reach the wait()ing thread when it already sleeps. This is assured by synchronized(this) ,which acquires the monitor. Any notify()ing thread must first acquire the monitor, which is not possible while the thread still runs in P(). > > Also, in many of the real applications I have worked on, Interrupted > Exceptions are not "should never happen" but a real fact of life and need > real handling. Shouldn't your design include something more meaningful, > such as either directly throwing InterruptedException so the application can > determine the appropriate course of action or something that lets them be > ignored or retried? Hmm. Can you explain the exact circumstances of InterruptedException being thrown ? > > > } > > count--; > > } > > } > > > > /** Release one resource item, thereby waking up a sleeping thread > > * if free resource count was zero. > > */ > > public void V(){ > > synchronized(this){ > > count++; > > if(count==1)notify(); > > } > > } > > } > > Also, what about the order in which the signals are granted? This version > simply relies on notify to choose the order, which may not be in the order > they were requested. I do not exactly understand what you are referring to - is it that notify() doesn't guarantee the order of sleeping threads woken up ? >And, of course, there is the whole time-out issue--I > don't want a broken subprocess to break my app as a whole. You could also state that you do not want a segmentation violation to stop a programm's execution. Yet all modern OSs terminate a programm which has a pointer problem. > > IMHO, I think the reason there are so many versions of Semaphore is that the > abstract concept (no matter how well implemented) is not sufficient and > people need different behaviors for different applications. Maybe there is some truth in this, but for the plain-vanilla Semaphore there are a number of implementation on the net (for example with notifyAll() or while(count==0) ) which are at least too complex for the purpose. > > Cheers, > Matt Humphrey [EMAIL PROTECTED] http://www.iviz.com/ ============================================================================== TOPIC: Servlet OutOfMemory on images. Please help me! http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/2b54ac9443545bf3 ============================================================================== == 1 of 1 == Date: Thurs, Nov 25 2004 7:49 pm From: Animanera Michael Borgwardt wrote: > Andrew Thompson wrote: > >> AFAIU, that is not the case. In fact I have a vague recollection* >> that I managed to 'catch' OOM errors before, there are two points to note >> >> 1) java.lang.OutOfMemoryError sub-classes Error, not Exception, so >> 2) The application's out of memory, so what are you going to do now? > > > Well, theoretically if you catch an OOME several methods back into > the stack, then a lot of objects created by the method calls inbetween > should be egligible for garbage collection, so there should be some > memory available. Of course you don't know how much... Sorry, probabily I do not explain my self very well (Please excuse me for my english) :-\ My environment is a SERVLET, therefore I've to deal with concurrent user access. The 1st code didn't work since it loaded (we say) 7 image in memory (cache) also if the operations were SEQUENTIAL. Do not charging the cache resolved the problem. BUT if 7 users CONCURRENTLY access to the servlet and execute the same code, the 7 images are *contemporarily* in memory, saturating it. My (ugly) idea on catching OOME was "if a user try to execute the resizing and this operation throw an OOME, it means that too user are executing this code, therefore for THIS user I sleep for a while loop since the operation doesn't throw an OOME". Simpler (and, maybe, better) solution should be declaring the resize method as SYNCHRONIZED therefore only ONE user at a time can execute the method (is it right, also if the method is static?). = no possibilities to saturate the memory; What do you think about it? Thank you, Bye, Animanera. :) ============================================================================== TOPIC: JSP Workflow FlowControl PageFlow Engine http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/acd037da0d51e674 ============================================================================== == 1 of 1 == Date: Thurs, Nov 25 2004 9:01 pm From: "Heiner Kücker" Hi all Sorry, my englisch is not good. I have written an JSP FlowControl Framework called 'Control and Command'. My Framework enabled to write a JSP application easy like an modefully DOS application like BASIC or CLIPPER. It closed the gap between Browser and Server presented by the request response cycle. Online demo is available on http://www.control-and-command.de The bottom of the demo pages shows the scripting source code with an arrow on the current source code line. This is an JSP Custom Tag for debug. An single step debug mode is available. The CnC-Language contents procedures and functions with parameters (per value or per reference) and control structures if/else if/else condition, while loop and do loop. Sorry, Documentation is completely written in german language. My Framework contents an DomainParser (parser for an Domain Specific Language), an Compiler and a Flow Processing Unit. It works with JSP Custom Tags. My framework helps you solving your painfully problems with the struts pageflow and code scattering in many xml and java files. The only necessary xml file is the web.xml . Its completely free. Im pleased over an positive feedback or success story by using my framework. Heiner Kuecker http://www.heinerkuecker.de JSP Page Flow WorkFlow FlowControl Navigation: http://www.control-and-command.de Expression Parser: http://www.heinerkuecker.de/Expression.html no struts ============================================================================== TOPIC: time factor for loops and arrays http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/165f1800f74e0914 ============================================================================== == 1 of 1 == Date: Thurs, Nov 25 2004 12:16 pm From: [EMAIL PROTECTED] (Yamin) Tom McGlynn <[EMAIL PROTECTED]> wrote in message news:<[EMAIL PROTECTED]>... <snip> > Greetings and TIA > > > If may well depend upon what the command you've represented as a comment > does. E.g., > > double array[100000][32]; > > for (i=0; i<100000; i += 1) { > for (j=0; j<32; j += 1) { > array[i][j] = i+j; > } > } > > will likely have much better memory behavior than > when the loops are in the other direction. As written the inner > loop deals with each 32 element array once and for all while putting the > loops in the other order makes it stride through memory 32 times and > likely requires many more transfers between cache and main memory. > Yeah, that's what I was thinking. I'll detail it a bit for curiousity sake. It might be page thrashing. Memory is only linear, so consider the compiler lays out the array of doubles as follows: a[x][y] a[0][0] a[0][1] a[0][2]...a[0][31]a[1][0]a[1][1]...a[99999][0]...a[99999][31] so as we see in this layout, all the y values for a particular x are laid out sequentially. Lets take an imaginary processor cache page size of 128 bytes. I'm being nice for this example assuming sizeof(double) == 4; So each cache page can hold exactly 32 doubles :) And lets assume there is only 1 page in the cache. Doing it this way, when the processor loads the value a[0][0], the values a[0][0] all the way to a[0][31] are cached. So as you go through the inner loop, you are very nicely accessing all these values...which are cached. When you move to the next 'x' index, you throw out these cached results and load in a[1][0] to a[1][31]. Its very nice for locality. Therefore, you only change the cache page x time...which in your case is 100000; Now for the sake of argument, lets say the array is laid out exactly the same as above, but you go through the loop the other direction. 1. you access a[0][0] 2. a[0][0] to a[0][31] are all loaded in 3. you access a[1][0] 4. a[1][0] is not in the cache, so it throws that out and loads in a[1][0] to a[1][31] 5. you access a[2][0] 6. a[2][0] is not in the cache, so it throws that out and loads in a[2][0] to a[2][31] Notice how at every access, you're throwing out what's in the cache and loading a new cache back in. How wasteful :) Of course a real processor has a much larger cache and the cache page size is not going to work out exactly on even bounds with your array...but that's the just of the idea. Here, you are swapping the cache page 100000*32 times. That's very bad :) Yamin ============================================================================== You received this message because you are subscribed to the Google Groups "comp.lang.java.programmer" group. To post to this group, send email to [EMAIL PROTECTED] or visit http://groups-beta.google.com/group/comp.lang.java.programmer To unsubscribe from this group, send email to [EMAIL PROTECTED] To change the way you get mail from this group, visit: http://groups-beta.google.com/group/comp.lang.java.programmer/subscribe To report abuse, send email explaining the problem to [EMAIL PROTECTED] ============================================================================== Google Groups: http://groups-beta.google.com
