I have tried several modifications of the code, and of the native method.
I think I have norrowed it down to this happening when you call a native
method that makes use of COM methods for the second time.
If I change the structure so that Connect is called twice (in different
sessions), then the second call causes the crash. Similarly with Search.
If I modify the native methods so that they don't call any COM methods (like
CoCreateInstance), then this doesn't happen. Neither does much else, as my
JNI dll is a wraper to a load of COM components that we already have...
I have tried messing with synchronize and SingleThreadModel, but I can't get
past this problem. Is there an issue about using aservlet to call COM
components. I can't believe I'm the first to try.
> -----Original Message-----
> From: A mailing list for discussion about Sun Microsystem's Java Servlet
> API Technology. [mailto:[EMAIL PROTECTED]]On Behalf Of Phil
> Lewis
> Sent: 06 September 1999 10:42
> To: [EMAIL PROTECTED]
> Subject: JNI method causing crash
>
>
> I have a native method that I can merrily invoke from java
> code,as many time
> as I like.
>
> However, if I attempt to invoke this method a second time from a servlet,
> then I get:
>
> java.exe - Application Error
> The instruction at "0x0020004d" referenced memory at "0x0020004d". The
> memory could not be "read".
>
> Click on OK to terminate the program
> Click on CANCEL to debug the program
>
>
> This error occurs after the servlet has actually completed all of its
> processing, and the browser has displayed the results.
>
> Oddly, If I call the method twice within the servlet, then it is OK. It is
> only on the second invocation of the servlet that problem occurs.
>
> I'm pretty sure it's something to do with the native method, because
> everything is fine if I comment out that call.
>
>
> Selecting CANCEL invokes the Visual C++ debugger, which usually shows the
> machine code where the error occurs (unless you have debug info). But it
> says:
>
> Error attaching to process
>
> Then:
>
> Unhandleed error in java.exe: 0xC0000005: Access violation.
>
> Any suggestions as to what may be happening (bearing in mind that
> I can call
> the method from a standard app with no problems) would be massively
> appreciated.
>
> Here's the servlet code:
>
>
>
> import java.io.*;
> import javax.servlet.*;
> import javax.servlet.http.*;
> import java.lang.Long;
> import java.lang.System;
>
> public class SearchBean extends HttpServlet implements SingleThreadModel
> {
> public native void connect(long DBID);
> public native synchronized void search(Object[][] results, long prodID,
> long maxReturns, boolean filter, String queryString);
>
> private boolean doneit = false;
>
> public void init(ServletConfig config)
> throws ServletException
> {
> if(!doneit)
> {
> try
> {
> doneit = true;
> System.loadLibrary("NREJBSearchProcessor"); //I've
> tried doing this
> in a static block, but there was no difference
> }
> catch(Exception e)
> {
> }
> }
> }
>
> public void doGet(HttpServletRequest req, HttpServletResponse res)
> throws ServletException, IOException
> {
> Long[][] results = new Long[2][];
> SearchBean sb = new SearchBean();
>
>
> try{
> sb.connect(1);
> sb.search(results, 1, 15, false, "product");
> }
> catch(Exception e)
> {
> System.out.println(e); //It doesn't seem to go into here
> }
>
> res.setContentType("text/html");
>
> PrintWriter out = res.getWriter();
>
> out.println("<HTML>");
> out.println("<HEAD><TITLE>Search Results</TITLE></HEAD>");
> out.println("<BODY>");
> out.println("<TABLE COLS=2 BORDER=1>");
> out.println("<TR><TD>ID</TD><TD>Score</TD></TR>");
>
> for(int i = 0; i < results[1].length; i++)
> {
> out.println("<TR><TD>" + results[0][i].intValue() + "</TD><TD>" +
> results[1][i].intValue()/10 + "</TD></TR>");
> }
> out.println("</TABLE></BODY></HTML>"); //This line is
> delivered to the
> browser
>
> }
>
> public String getServletInfo()
> {
> return "Search Servlet";
> }
> }
>
> I'm running on Windows 2000 Profession (NT5) Beta 3, using the http server
> that comes with JSDK 2.1, and the standard Sun 1.2 JVM.
>
> __________________________________________________________________
> _________
> 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