Monday, January 23, 2012

CancellableTask
Creating Robust JMS Applications
JMS and Transactions | Enterprise Messaging with the Java Message Service (JMS) | InformIT


JMS and Transactions

The JMS acknowledgment modes provide varying levels of reliability for message consumers, but enterprise applications often require stronger, transactional guarantees. For instance, an application might need to dequeue a message, update some database tables, and enqueue the message on another JMS queue. If any of these operations fails or a system failure occurs, the entire operation should roll back to its original state. JMS offers two transactional options: transacted sessions and an integration with the WebLogic Server's Java Transaction API (JTA) transaction service.

Using Transacted Sessions

Transacted sessions are used when transactional behavior is required within a single JMS session. Other resources such as database or EJB operations cannot participate in a transacted session's transaction. Passing a boolean true argument when the session is created creates a transacted session. The acknowledgment mode is also specified, but it is ignored for transacted sessions.
Session txSession = qCon.createQueueSession(
  true, /* transacted session */
  Session.AUTO_ACKNOWLEDGE /* IGNORED for transacted session */
  );
Transacted sessions use the chained transaction model. A transaction is always open for each transacted session. When the transaction is committed, the JMS implementation automatically starts a new transaction. The javax.jms.Session object includes commit() and rollback()methods for the JMS client to explicitly commit or roll back the associated transaction.
Both message producers and message consumers may use transacted sessions. When a message producer uses a transacted session, sent messages are buffered until the transaction commits. No message consumers will receive these uncommitted messages. When the message producer calls the session's commit method, the messages are all enabled for delivery. If the transaction aborts, the JMS implementation will discard the buffered messages.
With message consumers, transacted sessions control message acknowledgment. The consumer can receive multiple messages just like the CLIENT_ACKNOWLEDGE mode. When the associated transaction is committed, the JMS implementation acknowledges all messages received in the associated transaction. If the transaction aborts, the JMS implementation returns the messages to the associated queue or topic.
Transacted sessions are used when transactional behavior is required within a single JMS session. Other resources such as database or EJB operations cannot participate in a transacted session's transaction.

Using JTA Transactions with JMS

Transacted sessions enable a JMS producer or consumer to group messages into a single, atomic send or receive. However, a transacted session is only used within JMS. Many applications need JMS and JDBC or EJB work to participate in a single transaction. For instance, an application might dequeue a message containing a customer order and use the order information to update some inventory tables in the database. The order processing and the inventory update must be within the same transaction, so a transacted session is insufficient because it only handles JMS. The application must use a JTA javax.transaction.UserTransaction to wrap the JMS and JDBC work in a single transaction.
The JTA UserTransaction API may only be used with nontransacted sessions. A transacted session will not participate in any JTA transaction, and it will ignore any UserTransactioncommits or rollbacks.
The acknowledgment mode must be specified when creating a JMS session, but it is ignored when the UserTransaction API is being used.
Before using JTA UserTransactions with JMS, the server administrator must set theConnectionFactory's User Transactions Enabled checkbox in the WebLogic Server's Administration Console.
  QueueSession session = qCon.createQueueSession(
   false, /* not a transacted session */
   Session.AUTO_ACKNOWLEDGE
  );
The JMS client will use JNDI to find a reference to the server's JTA implementation.
  Context ctx = new InitialContext();

  UserTransaction tx = (UserTransaction)
   ctx.lookup("javax.transaction.UserTransaction");
The JMS client must use the UserTransaction's begin method to start a transaction. Unlike transacted sessions, the UserTransaction API is not a chained model, and clients must explicitly begin a transaction.
  // start transactional work
  tx.begin();
Now any JMS work performed in this session and JDBC or EJB operations will participate in this transaction. For instance, our message producer sends several messages within the transaction.
  msg.setText("Transacted Message-1");
  sender.send(msg);

  msg.setText("Transacted Message-2");
  sender.send(msg);
The sender might then perform some JDBC operations.
  // We have omitted the JDBC setup code, but this shows
  // executing a database insert within the same tx as our JMS
  // operations

  statement.executeUpdate (
    "INSERT INTO demoTable VALUES ('Hello', 'World')");
Finally, the transaction must be explicitly committed or rolled back.
  // commit our JMS and JDBC work

  tx.commit ();
When the transaction commits, any JMS messages produced within the transaction are enabled for delivery. Any received messages will be acknowledged with a commit. A transaction abort will release any sent messages while received messages will be returned to their JMS destination and redelivered.
JTA UserTransactions should be preferred to transacted sessions since the transaction can enlist other resources such as JDBC or EJB access.
Memory Analyzer Blog: Automated Heap Dump Analysis: Finding Memory Leaks with One Click
Memory Analyzer Blog: Heap Dump Analysis with Memory Analyzer, Part 2: Shallow Size
Memory Analyzer Blog: Heap Dump Analysis with Memory Analyzer, Part 1: Heap Dumps
Memory Analyzer Blog
Eclipse Memory Analyser (MAT) - Tutorial
MemoryAnalyzer - Eclipsepedia
Office Language Packs 2010 features and benefits - Office Language Packs - Office.com

Sunday, January 22, 2012

ExecutorCompletionService (Java Platform SE 6)
CompletionService (Java Platform SE 6)
Android get attached filename from gmail app - Stack Overflow
Android Intent like Gmail's attach Intent - Stack Overflow
水木社区-用户信件服务
按照《云中读书》的方法来做,对于只想把一个网页的内容通过Android的TTS引擎读出来这样简单的目的来说还是太繁重了。现在知道Moon+ Reader可以支持HTML,那么转换这个环节可以省去,只需要共享出链接就可以。比较恶心的是,Android的浏览器不能保存当前页面。不过它可以保存link,这样也基本上足够了。
于是我现在的做法是:利用Blogger.com建立一个垃圾blog,专门存放我要看的链接,然后通过Android浏览器下载来看,再用Moon+ Reader来读出来。如果我想读某小部分内容,这个方法也合用。
只要bookmark自己的垃圾blog地址,操作起来就很方便了。
android - Gmail attachment and custom extension - Stack Overflow