Is it legal to use Vector in EJB?

Chapter 24 of the EJB spec states:
"An enterprise Bean must not use thread synchronization primitives to synchronize execution of multiple instances."
As far as I know Vector ist thread save.
Does this mean you must not use Vector in EJB? Or is it allowed to use Vector as only one bean instance accesses one Vector instance?

I'd sure like to hear a clear answer to this question. I've been tasked with adding an EJB interface to an existing server application. Right now, we have 2 main methods of sending requests to the server, RMI and IP. We have clients that are requesting an EJB interface. What I'd like to do is create a Session bean( haven't decided on Stateless or Stateful yet ) that invokes the same underlying objects that the RMI and IP objects use. However, those classes were not written with EJB's in mind. They start threads. They access files. They have static data which is manipulated. All those things are forbidden( or at least, strongly discouraged ) in the EJB spec, as I understand it.
Of course, I could create a Session bean that used the existing RMI or IP interface to talk to an instance of our application running in a different JVM, which would eliminate the problem. But that seems like a bit of a hack to me.
Marc Robertson
Staff Consultant
DST Systems, Inc.

Similar Messages

  • Using Vectors in Entity Beans

    Hello,
    Can I use vectors in entity and store them in Tables directly as binary objects.I have tried making that bean but facing problem in retriving data from table using EJB-QL.Here are code snippets:
    -------public abstract class CartEntityBean implements EntityBean {
         private EntityContext ctx;
         public abstract String getCartId();
         public abstract Vector getItems();
         public abstract void setCartId(String CartId);
         public abstract void setItems(Vector items);
    public String ejbCreate(String cartId,Vector items) throws CreateException {
              setCartId(cartId);
              return cartId;
    rest other methods omitted
    public interface CartHomeInterface extends EJBHome{
    public CartRemoteInterface create (String cartId,Vector items )throws CreateException,RemoteException ;
    public CartRemoteInterface findByPrimaryKey(String pk) throws FinderException, RemoteException;
    public Collection findmyItems() throws FinderException, RemoteException;
    I am using Cloudscape as Database.
    Please help weather I can use Complex objects in Entity Beans or Not

    this is no good idea to store the cart-items as a java-vector. you should create a entity bean cart and a entity bean cartItem. then create a cmr between the two entity beans.

  • Exception IndexOutOfBoundsException using Vector. Christmas homework!

    Hi everyone, I'm not a java expert (almost a newbie, I would say) and this is the first time I post anything in a Forum. I have the following piece of code:
    public class Test extends javax.swing.JFrame {
    private java.util.Vector list;
    public Test() {
         super("test");
         list = new java.util.Vector();
         javax.swing.JButton add = new javax.swing.JButton("Add");
         add.addActionListener(new java.awt.event.ActionListener() {
              public void actionPerformed(java.awt.event.ActionEvent e) {
              String value = "new element";
              System.out.println("size: "+list.size());
              list.add(value);
              int i = list.size();
              System.out.println("size + 1: "+i);
              /**/System.out.println("elem i: "+ (String)list.get(i));
         getContentPane().add(add);
         pack();
         setVisible(true);
    public static void main(String[] args) {
         new Test();
    and when I run it I have the following printout:
    size: 0
    size + 1: 1
    java.lang.ArrayIndexOutOfBoundsException: Array index out of range: 1
    at....
    (omissis)
    Does anyone have any idea of why? how can I solve the problem? Isn't Vector supposed to be "dynamic"?
    Elsewhere I use Vectors with no problems but I am not accessing it right after having added any element, rather I return it as the result of some elaboration and then access it.
    I know it's Christmas time and so I wish you all Merry Christmas and Happy new Year. I hope someone has time to answer me over this holydays.
    Thanks anyway,
    Rosario

    Does anyone have any idea of why? how can I solve the
    problem? Isn't Vector supposed to be "dynamic"?You try to access an element after the last element. When you set i = list.size(), i will be the index of the last element plus one. This is because indices count from 0.
    It is the list.get(i) that causes the problem.
    Søren

  • Is there a way to "mix" colors using vectors?

    Here's my problem: I'm not a very technical and detailed artist, and I'm not trying to be. My works is pretty cartoonish actually, so I never dabble with the paintbrush and always use vectors. Anyhow, I was wondering, if I want to draw, using vectors, a guy with half of his legs in a pool, and half not, how would I go about coloring that? I mean, I'm intending to make the man pinkish, and the water light bluish, but how can I achieve the mixture, a combination of the two, for the half of the legs underwater? I'm not seeking color recommendations (for the legs) by the way. Is there a way to combine two colors to achieve an in-between ground?

    Put the legs on one layer and put the water on another layer above/in-front and adjust the opacity of the water-layer to let some of the leg-layer show through.  If you don't want to construct your cartoon using layers which is one of Photoshop's main benefits, you can figure out what color to make the wet leg with by creating a swatch of leg color in one layer and then make a water-colored layer in front/above it and adjust the opacity then use the eyedropper to sample the color of the combination.
    Of course in a real situation with the observer above the level of the water looking through it at an angle, the leg would become bluer the further into the water it went because there would be more water between the foot and the observer than say the knee and the observer and you'd want to make a gradient of color or gradient of transparency using a layer mask with a black-to-white gradient in the mask instead of just one opacity setting, and there would also be some size and offset of the leg due to refraction of the water, but as you said you're not a detailed artist.

  • Insert data into table from JSP page using Entity Beans(EJB 3.0)

    I want to insert data into a database table from JSP page using Entity Beans(EJB 3.0).
    1. I have a table 'FRIENDS', (in Oracle 10g database).
    2. It has two columns, 'NAME' and 'CITY'. Both have datatype strings(varchar2).
    3. Now from a JSP page, having two textfields, 'NAME' and 'CITY', I want to insert data into table 'FRIENDS'.
    4. In between JSP and database is a Entity Bean(EJB 3.0) and a stateless session bean.
    5. I am using JDev as editor.
    Please provide me code ASAP or link with similar example.
    Thank you.
    Anurag

    Hi,
    I am also trying that scenario. So u can
    Post the jsp form data to a Servlet which will act as a Controller.
    In the servlet invoke the business method.
    Similar kind of app is in www.roseindia.net
    Hope this would help u.
    Meanwhile if u get any optimal solution, pls post it.
    Thanks,
    Happy Java Coding.

  • How am I able to use an injected EJB in a Managed Bean Constructor?

    JSF 1.2
    EJB 3.0
    Glassfish v1
    Summary:
    Managed bean injected EJB is null when referencing EJB var in constructor.
    Details:
    In my managed bean, I have a constructor that tries to reference an injected EJB, such as:
    public class CustomerBean implements Serializable {
    @EJB private CustomerSessionRemote customerSessionRemote;
    public CustomerBean() {
    List<CustomerRow> results = customerSessionRemote.getCustomerList();
    }The call within the constructor to customerSessionRemote is null - I've double checked this in Netbeans 5.5.
    How am I able to use an injected EJB in a Managed Bean Constructor?
    Thanks,
    --Todd                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

    OK, I was reading the article Web Tier to Go With Java EE 5: A Look at Resource Injection and I understand your statement too.
    Is there any way possible to Inject the EJB prior to the bean instance creation at all?
    Maybe, I need to approach it with the old fashion Java EE 1.4 route and using JNDI in the PostConstruct annotated method to reference the EJB in the managed bean.
    This had to been thought out before, I don't understand why a manged bean's life cycle places any injections at the end of the bean creation.
    Also, now that I understand that the @PostConstruct annotated method will be called by the container after the bean has been constructed and before any business methods of the bean are executed.
    I am trying to reference my EJB as part of the creation of the managed bean.
    What happens: the JSF page loads the managed bean and I need to populate a listbox component with data from an EJB.
    When I try to make the call to the EJB in the listbox setter method, the EJB reference is null.
    Now, I'm not for sure if the @PostConstruct annotation is going to work... hmmmm.
    ** Figured it out. ** I just needed to move the EJB logic that was still in the setter of the component I wanted to populate into the annotated PostConstruct method.

  • How to use Vector or other ArrayList etc to store my JTree??

    How to use Vector or other ArrayList etc to store my JTree??
    Dear friends,
    I have following I posted before, but not get satisfactory answer, so I modify and repost again here.
    I have following code can add classes and students in the JTree,
    in class Computer Science, it has student Bill Brien,
    in Math, no,
    Then I I add Student Nancy, Laura, Peter into Computer Science Class,
    add AAAA, BBB, CCC into Math class,
    I create a new class called Chemistry, then I add DDD int Chemistry;
    so this JTree is dynamically changed,
    [1]. How can I dynamically save my current JTree with all above tree structure and its nodes in a Vector or ArrayList(not sure which one is best)??
    see code below:
    import java.awt.BorderLayout;
    import java.awt.Container;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import javax.swing.JButton;
    import javax.swing.JFrame;
    import javax.swing.JOptionPane;
    import javax.swing.JPanel;
    import javax.swing.JScrollPane;
    import javax.swing.JTree;
    import javax.swing.tree.DefaultMutableTreeNode;
    import javax.swing.tree.DefaultTreeModel;
    public class ModelJTreeTest extends JFrame {
      private JTree tree;
      private DefaultTreeModel model;
      private DefaultMutableTreeNode rootNode;
      public ModelJTreeTest() {
        DefaultMutableTreeNode philosophersNode = getPhilosopherTree();
        model = new DefaultTreeModel(philosophersNode);
        tree = new JTree(model);
        JButton addButton = new JButton("Add Class/Students");
        addButton.addActionListener(new ActionListener() {
          public void actionPerformed(ActionEvent event) {
            addPhilosopher();
        JButton removeButton = new JButton("Remove Selected Class/Students");
        removeButton.addActionListener(new ActionListener() {
          public void actionPerformed(ActionEvent event) {
            removeSelectedPhilosopher();
        JPanel inputPanel = new JPanel();
        inputPanel.add(addButton);
        inputPanel.add(removeButton);
        Container container = getContentPane();
        container.add(new JScrollPane(tree), BorderLayout.CENTER);
        container.add(inputPanel, BorderLayout.NORTH);
        setDefaultCloseOperation(EXIT_ON_CLOSE);
        setSize(400, 300);
        setVisible(true);
      private void addPhilosopher() {
        DefaultMutableTreeNode parent = getSelectedNode();
        if (parent == null) {
          JOptionPane.showMessageDialog(ModelJTreeTest.this, "Select Class", "Error",
              JOptionPane.ERROR_MESSAGE);
          return;
        String name = JOptionPane.showInputDialog(ModelJTreeTest.this, "Add Class/Students:");
        model.insertNodeInto(new DefaultMutableTreeNode(name), parent, parent.getChildCount());
      private void removeSelectedPhilosopher() {
        DefaultMutableTreeNode selectedNode = getSelectedNode();
        if (selectedNode != null)
          model.removeNodeFromParent(selectedNode);
      private DefaultMutableTreeNode getSelectedNode() {
        return (DefaultMutableTreeNode) tree.getLastSelectedPathComponent();
      private DefaultMutableTreeNode getPhilosopherTree() {
        DefaultMutableTreeNode rootNode = new DefaultMutableTreeNode("Students");
        DefaultMutableTreeNode ancient = new DefaultMutableTreeNode("Computer Science");
        rootNode.add(ancient);
        ancient.add(new DefaultMutableTreeNode("Bill Brian"));
        DefaultMutableTreeNode math = new DefaultMutableTreeNode("Maths");
        rootNode.add(math);  
        DefaultMutableTreeNode physics = new DefaultMutableTreeNode("Physics");
        rootNode.add(physics);
        return rootNode;
      public static void main(String args[]) {
        new ModelJTreeTest();
    }the actual Tree dynamically created somehow looks like following:
                             |            1.Peter
                             |---CS---    2. Nancy
                             |            3. Laura
                             |            4.Brian
                             |
    Root(University): -------|---Math- 1.AAA
                             |            2.BBB
                             |            3.CCC
                             |
                             |
                             |---Chemistry- 1. DDDThanks a lot
    Good weekends

    you can't directly store a tree in a list.Ummm... Just to be contrary... Yes you CAN store a tree in a table.... In fact that's how the windows file system works.
    Having said that... you would be well advised to investigate tree data-structures before resorting to flattening a tree into a list.
    So... Do you have a specific requirement to produce a List? Your umming-and-erring about Vector vs ArrayList makes it sound like you're still at the stage of choosing a datastructure.
    Cheers. Keith.

  • How to use vector in JTable? Please help......

    Hi there
    I can use JTable using object array to manupulate data but it has a limitation of defining number of rows of the array. Alternatively i want to use vector. Anyone help me how to convert to using vector.
    Regards.
    mortoza, Dhaka

    hi,
    you could either use javax.swing.table.DefaultTableModel because this class uses a java.util.Vector for data storage or you could implements your own TableModel by extending javax.swing.table.AbstractTableModel.
    best regards, Michael

  • Do i have to use JNDI with EJBS?

    Hi
    I want to use JNDI to lookup a system which i will send messages to using JMS. I would like to have some java classes on Tomcat to do the job. But...whenever i hear about JNDI it is always in relation to EJBs. Can i only use JNDI with EJBS?
    If i can use JNDI is there anything important i need to know about.
    Thanks in advance!
    San H.

    You can definitely use JNDI outside of EJB's - in particular, it's a great interface for dealing with LDAP servers, even securely, and can also be used for DNS interfacing, COS, RMI registries, etc.
    While JNDI was chosen as the method by which J2EE components can locate other components in a distributed environment, it's by no means limited to that task :) It's a wonderful API, and in terms of things you need to know, most everything is covered fairly well at the JNDI tutorial in the various trails that are mapped out there.
    http://java.sun.com/products/jndi/tutorial/
    Good luck!
    James
    James Manning | Principal Engineer
    Porivo Technologies, Inc.
    919.806.0566 | [email protected]
    http://www.porivo.com/
    Measuring end-to-end Web performance.
    Register for a FREE Performance appraisal:
    http://www.porivo.com/peerReview/eval.html

  • Do i have to use JMS with EJBS?

    Hi
    I want to use JMS as a messaging system (a queue) between my system and someone elses. I would like to have some java classes on Tomcat to do the job. But...whenever i hear about JMS i always hear it in relation to EJBs. Can i only use JMS with EJBS?
    If i can use JMS is there anything important i need to know about.
    Thanks in advance!
    San H.

    As far as I understand you are use JNDI and JMS is not bound with EJB's. These are java API's which are independent. Like JDBC you can use with Servlets, Applets, standalone applications, EJB, JMS etc etc.......
    In the same way you can use JNDI and JMS with diferent API. And the important feature of Java is that all java API interact with each other when these are independent. I would appricate comments of everyone......................Thanks

  • Problems using Vector in Flex Builder 3

    I've been using Vector with no problems in Flash Builder Beta, but when I try the same thing in Flex Builder 3, the compiler throws a fit when I use it. 
    public function PuzzleEvent(type:String, pieces:Vector.<Sprite>, bubbles:Boolean=false, cancelable:Boolean=false)
         //handle PuzzleEvent
    The other strange thing is, Flex automatically adds this line when I use vector:
    import __AS3__.vec.Vector;
    An import shouldn't be necessary should it?  Vector is in the top level package right?  With or without that import statement, I get compile errors.  Has anyone else had such problems with vector in Flex Builder?
    Dan

    The only way I was ever able to solve this problem was to use Flex builder Beta and now Flash Builder 4.  I did target flash player 10.0.0, but I still never could get it to work.  At least it works in Flash Builder 4.

  • Using InputStream on EJB method

    Hi everyone,
    i was looking for a way to use InputStream or anything else related to the java.io package on my EJB method. This is the first time that i need to do something like that, so i made a research and i figure out that is impossible use any kind of the io package when i using EJB. Is that true?...
    if this is true, could anyone help me how i can save something on my server using EJB?
    Thanks in Advance

    hi,
    i looked in some forums, and talk with some people who use EJB for so long, and all answers took me to the conclusion that is totally not recommended using streams on ejb methods...i haven't looked on ejb specification to really see if its true...
    Besides, i tried in other way..... first i created my EJB method with a byte[] parameter, and a "service" class which convert this array to an InputStream..and record the file on server...i did a client to test and apparently works without errors, i don't receive any exceptions, so i suppose that at least this part is correct, but i having another problem....
    by the way, anyone know how can i save a certificate on a Keystore??...i'm trying that:
    keyStore = manager.getKeystore("DEFAULT");
         keyStore.load(is, password.toCharArray());     attempting that "is" is the InputStream (same of the problem above) and the second parameter is the password....this code belongs to a method on the "service class" that i mentioned before....
    but nothing happens when i run my app. anyone could help me??
    Thanks in Advance

  • Defining Business Operations using remote session EJBs for WLI2.1

    Hello all,
    I'm having a deployment issue with WLI 2.1. Is it true that in order to define
    a Business Operation in WLI 2.1 that uses a session EJB, the EJB MUST be deployed
    in the same JNDI tree (WLS instance) that WLI is running on? Is everyone just
    running one admin server that hosts WLI and all other applications on the same
    instance?
    I'd like to have WLI running on one machine and have my applications running on
    another, but at this point seems unobtainable because you cant supply a t3 URL
    to that separate machine when defining Business Operations...
    Any help would be appreciated,
    Jon

    I am new to WLPI and have run across this problem as well. Could you
    provide more detail your proxy session bean and maybe include some
    example code? Thanks.
    Regards,
    Rick H.
    "Paul Rooney" <[email protected]> wrote:
    >
    I have come accross the same problem - solved it by using a "proxy" session
    bean
    that knows how to call out to all the Remote EJBS that I need. This "proxy"
    session
    bean is deployed with wlpi application.
    "Erik Godding Boye" <[email protected]> wrote:
    We would like to define business operations in WLI calling EJBs on a
    remote machine.
    It seems like the EJB have to be deployed locally to appear in the (JNDI)
    drop-down
    list when defining the business operation.
    Is the only way to achieve this functionality to write (or generate)
    some kind
    of wrapper EJB that will be deployed locally, or do you have other suggestions?
    Regards,
    E
    PS: We're using WLI 2.1 running on WLS 6.1 SP1

  • I am using webservice in ejb but it is giving Naming exception in NetWeaver

    hai
    this Guru.
    i am working as javadeveloper .
    in my project i am using webservices in ejbs.
    i am using netweaverdeveloper .
    my problem is whlie accessing webservices in ejbs it is giving Namingexception .
    please tell me the procedure for accesing WEBSERVICES IN EJB BY USING NETWEAVER DEVELOPER STUDIO.
                              THANQQQQQ
                       GURU FROM MOBILEONE PTV LIMITED
                              HYDERABAD
                              INDIA

    Hi Guru,
    Refer these links
    Accessing the Web Services Context from a WS-EJB -> 
    http://help.sap.com/saphelp_webas630/helpdata/en/a6/835f3e1e7d7937e10000000a114084/content.htm
    Accessing the web service from webdynpro ->
    https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/docs/library/uuid/9fc0e990-0201-0010-199c-e38fc6dafb5d
    Regards,
    Uma

  • How to define DefaultTableModel to use vector data?

    Hi ...
    I want to show files data in a jtable which consist of files (Name,size,path) I want to use vectors for remove and add methods. The problem is with data vector I tried to define it as
    Vector <Vector[][]>data;I get always an error when I tried to add data to data vector so where is my problem?
    Thanks.
    Feras

    Vector <Vector[][]>data;You are confusing 2Dimensional arrays with Vectors. When using Vectors you need to create a Vector of Vectors. The code should be something like this;
    Vector<Vector> data = new Vector<Vector>();
    Vector<Object> row1 = new Vector<Object>();
    row1.add(name);
    row1.add(size);
    row1.add(path);
    data.add(row);Presumably the code to add the rows would be in a loop.

Maybe you are looking for

  • Text wrap crash ID6 in OSX8

    ID CS6 - 8.0.0.370 OS 10.8 (12A269) Trying to reposition a text-wrapped box containing grouped text and a small logo within main A5 size page text causes ID6 to crash.  Have submitted a crash repro but no fix found yet. Recreating the inserted box el

  • Error installation - Payload path does not exist and no media record specified.

    Hi all, When I tried to install the photosohop CS5, the below errors keep prompting out. Can anyone help me solve these errors! Thanks! Exit Code: 7 -------------------------------------- Summary -------------------------------------- - 0 fatal error

  • Search window in finder is too small

    Hi When I perform a search in a finder window (cmd + F) the window that opens is tiny (about 10% of my screens) and includes only two items: Search "This Mac" and a second button. The files found can only be sorted using three arguments (name, type a

  • Document Integration in BPS Layouts

    Hi If I create a document for a particular <b><b>0SEM_POS</b>IT</b> value (For example 600000), for the keyfigure <b>0Amount</b> and for a given Layout, the same document appears in the other Layouts also eventhough other Layouts are under different

  • Converting Smartform in to PDF-Reg

    Hi, We have a issue. When we try to convert the SAP Script or Smart form in to PDF file using standard program,its not converting the BARCODES properly. What could be the reason and how to acheive it. Regards A.Sureshbabu