commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Martin Cooper <mart...@apache.org>
Subject Re: Is DiskFileItemFactory Thread Safe?
Date Fri, 05 Feb 2010 05:21:48 GMT
Unless you're using a truly antique version of Java, the cost of
repeatedly instantiating DiskFileItemFactory is entirely negligible.
The constructor does next to nothing, and the JVM already optimizes
repeated class instantiations almost out of existence. If you are
seeing performance issues with heavy load on your servlet, this is
_not_ what you need to be looking at, believe me.

To answer your question, though, the class is here:

http://svn.apache.org/repos/asf/commons/proper/fileupload/trunk/src/java/org/apache/commons/fileupload/disk/DiskFileItemFactory.java

from which you can see that there's not a lot going on in there.

--
Martin Cooper


On Thu, Feb 4, 2010 at 10:25 AM, evebill8 <evebill8@hotmail.com> wrote:
>
> I have a servlet that will handle few hundread thousand requests per day.  I
> am using the commons FileUpload to loop thru the fields and file items.
> Here is the code
>
>
>    public void doPost(HttpServletRequest req, HttpServletResponse res)
>            throws ServletException, IOException {
>
>        try {
>            DiskFileItemFactory factory = new DiskFileItemFactory();
>
>            ServletFileUpload upload = new ServletFileUpload(factory);
>            List<FileItem> items = upload.parseRequest(req);
>
>            for (FileItem item : items) {
>                ....
>            }
>        }
>        catch (Exception e) {
>            ...
>        }
>    }
>
> Since the servlet is being called so many times, can I make the
> DiskFileItemFactory global static so it won't create the factory object so
> many times?  In sum, is DiskFileItemFactory class thread safe?
>
>
>    DiskFileItemFactory factory = new DiskFileItemFactory();
>
>    public void doPost(HttpServletRequest req, HttpServletResponse res)
>            throws ServletException, IOException {
>
>        try {
>
>            ServletFileUpload upload = new ServletFileUpload(factory);
>            List<FileItem> items = upload.parseRequest(req);
>
>            for (FileItem item : items) {
>                ....
>            }
>        }
>        catch (Exception e) {
>            ...
>        }
>    }
>
> Thanks!
>
> --
> View this message in context: http://n4.nabble.com/Is-DiskFileItemFactory-Thread-Safe-tp1469216p1469216.html
> Sent from the Commons - User mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
> For additional commands, e-mail: user-help@commons.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org


Mime
View raw message