Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java EE programmers do not write to files

Today one person told to me that "Java EE programmers do not write to files". Why can I not write to files from within a Java EE container (for example from JBoss)? What is wrong?

like image 308
Volodymyr Bezuglyy Avatar asked Nov 24 '09 11:11

Volodymyr Bezuglyy


2 Answers

You should do everything within the Java EE container itself: you can have no certainty that you will have any consistent access to the filesystem. There are many reasons for this, the most obvious being that applications running within a container will have:

  • no certainty that any subsequent invocation of an EJB would even be on the same physical server with access to the same files/filesystem (e.g. upon clustering)
  • no possibility of interfering with each other (multiple applications attempting to write to the same file)
  • no security issues (one app writing confidential data which another app could read)

You should also assume that you shouldn't:

  • create your own threads (the container will manage this for you; if you create your own you may starve other applications in the container of CPU time)
  • use socket-IO (also has security issues)
like image 199
oxbow_lakes Avatar answered Sep 22 '22 15:09

oxbow_lakes


The best page to look at is this one: http://www.oracle.com/technetwork/java/restrictions-142267.html

It covers in detail the restrictions over the Java EE programming model.

Apart from the point mentionned above Security, Portability, Clustering, Threading also consider transactions and error handling (File systems are not transactional).

There is however no black magic happening in the JVM and you can create files (as long as you have the corresponding rights), use static variables, and create threads if you know what you're doing.

Better take the time to understand why these restriction are usually suggested, than to jump and write a JCA connector for the sake of being compliant.

like image 27
ewernli Avatar answered Sep 20 '22 15:09

ewernli