diff options
| author | Sven Eisenhauer <sven@sven-eisenhauer.net> | 2023-11-10 15:11:48 +0100 |
|---|---|---|
| committer | Sven Eisenhauer <sven@sven-eisenhauer.net> | 2023-11-10 15:11:48 +0100 |
| commit | 33613a85afc4b1481367fbe92a17ee59c240250b (patch) | |
| tree | 670b842326116b376b505ec2263878912fca97e2 /Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/session/stateful/CountClient.java | |
| download | Studium-master.tar.gz Studium-master.tar.bz2 | |
Diffstat (limited to 'Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/session/stateful/CountClient.java')
| -rw-r--r-- | Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/session/stateful/CountClient.java | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/session/stateful/CountClient.java b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/session/stateful/CountClient.java new file mode 100644 index 0000000..3536705 --- /dev/null +++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/session/stateful/CountClient.java @@ -0,0 +1,63 @@ +package examples.session.stateful;
+
+import javax.naming.*;
+
+/**
+ * This class is a simple client for a stateful session bean.
+ *
+ * To illustrate how passivation works, configure your EJB server
+ * to allow only 2 stateful session beans in memory. (Consult your
+ * vendor documentation for details on how to do this.) We create
+ * 3 beans in this example to see how and when beans are passivated.
+ */
+public class CountClient {
+
+ public static final int noOfClients = 3;
+
+ public static void main(String[] args) {
+ try {
+ /* Get a reference to the bean */
+ Context ctx = new InitialContext(System.getProperties());
+
+ /* An array to hold the Count beans */
+ Count count[] = new Count[noOfClients];
+ int countVal = 0;
+
+ /* Create and count() on each member of array */
+ System.out.println("Instantiating beans...");
+ for (int i = 0; i < noOfClients; i++) {
+ count[i] = (Count) ctx.lookup(Count.class.getName());
+
+ /* initialize each bean to the current count value */
+ count[i].set(countVal);
+
+ /* Add 1 and print */
+ countVal = count[i].count();
+ System.out.println(countVal);
+
+ /* Sleep for 1/2 second */
+ Thread.sleep(100);
+ }
+
+ /*
+ * Let's call count() on each bean to make sure the
+ * beans were passivated and activated properly.
+ */
+ System.out.println("Calling count() on beans...");
+ for (int i = 0; i < noOfClients; i++) {
+
+ /* Add 1 and print */
+ countVal = count[i].count();
+ System.out.println(countVal);
+
+ /* call remove to let the container dispose of the bean */
+ count[i].remove();
+
+ /* Sleep for 1/2 second */
+ Thread.sleep(50);
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+}
|
