[JBoss XML Binding Development] - Re: XB profiling during the AS start-up
by alex.loubyansky@jboss.com
I've run simple comparison tests for fastjaxb from resteasy and xb based on the "person" test from fastjaxb.
The results don't look that promising for fastjaxb, especially taking into account its binding features at this point are still primitive.
repetitions - number of unmarshallings of Person
total - total time in ms for all the repetitions
avg - average time ms for single repetition
repetitions 1
fast jaxb total=139, avg=139.0
xb total=47, avg=47.0
repetitions 10
fast jaxb total=151, avg=15.1
xb total=106, avg=10.6
repetitions 100
fast jaxb total=249, avg=2.49
xb total=286, avg=2.86
repetitions 1000
fast jaxb total=1057, avg=1.057
xb total=1402, avg=1.402
Here is the test
public class FastJaxbUnitTestCase extends TestCase
| {
| public FastJaxbUnitTestCase()
| {
| }
|
| private long repetitions = 1000;
| public void testFastJaxb() throws Exception
| {
| ParsingCommand c = new FastJaxbParsing(repetitions);
| c.run();
| System.out.println("fast jaxb total=" + c.getTotal() + ", avg=" + c.getAverage());
| }
|
| public void testXB() throws Exception
| {
| ParsingCommand c = new XBParsing(repetitions);
| c.run();
| System.out.println("xb total=" + c.getTotal() + ", avg=" + c.getAverage());
| }
|
| private static class XBParsing extends ParsingCommand
| {
| private static final UnmarshallerFactory factory = UnmarshallerFactory.newInstance();
| private SchemaBinding schema;
|
| protected XBParsing(long repetitions)
| {
| super(repetitions);
| }
|
| @Override
| protected void setup() throws Exception
| {
| super.setup();
| schema = JBossXBBuilder.build(Person.class);
| }
|
| @Override
| protected void parse() throws Exception
| {
| Unmarshaller unmarshaller = factory.newUnmarshaller();
| unmarshaller.unmarshal(xmlUri, schema);
| }
| }
|
| private static class FastJaxbParsing extends ParsingCommand
| {
| private static SAXParserFactory factory = SAXParserFactory.newInstance();
| static
| {
| factory.setNamespaceAware(true);
| }
|
| private Sax sax;
|
| protected FastJaxbParsing(long repetitions)
| {
| super(repetitions);
| }
|
| @Override
| protected void parse() throws Exception
| {
| SAXParser parser = factory.newSAXParser();
| parser.parse(xmlUri, sax);
| }
|
| @Override
| protected void setup() throws Exception
| {
| super.setup();
| HashMap<String, Handler> map = new HashMap<String, Handler>();
| map.put("urn:person", new Person_Parser());
| sax = new Sax(map);
| }
| }
|
| private static abstract class ParsingCommand
| {
| protected long repetitions;
| protected long total;
| protected String xmlUri;
|
| protected ParsingCommand(long repetitions)
| {
| this.repetitions = repetitions;
| }
|
| public long getTotal()
| {
| return total;
| }
|
| public double getAverage()
| {
| return ((double)total)/repetitions;
| }
|
| public long getRepetitions()
| {
| return repetitions;
| }
|
| protected void setup() throws Exception
| {
| xmlUri = Thread.currentThread().getContextClassLoader().getResource("person.xml").toExternalForm();
| }
|
| protected abstract void parse() throws Exception;
|
| public void run() throws Exception
| {
| setup();
|
| for(int i = 0; i < repetitions; ++i)
| {
| long start = System.currentTimeMillis();
| parse();
| total += System.currentTimeMillis() - start;
| }
| }
| }
| }
View the original post : http://www.jboss.org/index.html?module=bb&op=viewtopic&p=4257878#4257878
Reply to the post : http://www.jboss.org/index.html?module=bb&op=posting&mode=reply&p=4257878
15 years, 3 months
[JBoss Messaging Development] - Re: Fail to get a remote JMS Session due to NullPointerExcep
by belcar
Yes, I've removed the server/default/deploy/jms folder but the issue remains. The code works on Windows, but on linux with remoting this issue shows up. Here's the code that makes the connection:
<bean id="jndiTemplate" class="org.springframework.jndi.JndiTemplate">
| <property name="environment">
| <props>
| <prop key="java.naming.factory.initial">org.jnp.interfaces.NamingContextFactory</prop>
| <prop key="java.naming.provider.url">jnp://someIP:1099</prop>
| <prop key="java.naming.factory.url.pkgs">org.jboss.naming:org.jnp.interfaces</prop>
| </props>
| </property>
| </bean>
|
| <bean id="threadPoolSize" class="java.lang.Integer">
| <constructor-arg value="${threadPoolSize}"/>
| </bean>
|
| <bean id="jmsConnectionFactory" class="org.springframework.jndi.JndiObjectFactoryBean">
| <property name="jndiTemplate"><ref bean="jndiTemplate" /></property>
| <property name="jndiName" value="/ConnectionFactory"/>
| </bean>
|
| <bean id="requestQueue" class="org.springframework.jndi.JndiObjectFactoryBean">
| <property name="jndiTemplate"><ref bean="jndiTemplate" /></property>
| <property name="jndiName" value="${queue}"/>
| </bean>
public class StartupListener implements ServletContextListener {
| private static final Log log = LogFactory.getLog(StartupListener.class);
| private static Connection connection;
| private static Session session;
| private static MessageConsumer consumer;
| private static Boolean run = Boolean.TRUE;
| private static ExecutorService pool;
| private static Thread daemonThread;
| private static final String PREFIX = " ~~ ";
| private static MeteoService metService;
|
| /**
| * Startup trigger of the application.
| */
| public void contextInitialized(ServletContextEvent ctx) {
| log.info("==== Initializing ServiceBroker");
|
| logInfo("Creating polling thread ...");
| daemonThread = new Thread(new MessageDispatcher());
|
| try {
| ApplicationContext _ctx = WebApplicationContextUtils.getWebApplicationContext(ctx.getServletContext());
| initializeWorkerThreadPool(_ctx);
| initializeJMSEnvironment(_ctx);
|
| metService = (MeteoService) _ctx.getBean("metService");
|
| logInfo("Starting the Session ...");
| connection.start();
|
| logInfo("Starting a Daemon Thread responsible for message dispatching ...");
| daemonThread.start();
|
| log.info("==== ServiceBroker initialized successfully");
| } catch (Throwable e) {
| log.fatal(e.getMessage(), e);
| }
| }
|
| /**
| * This is a context lifecycle (callback) method.
| * The Servlet Context is being destroyed by the Container due to a shutdown.
| * As a result we need to clean up our privately managed resources.
| */
| public void contextDestroyed(ServletContextEvent ctx) {
| synchronized (run) {
| log.info("==== Shutting down PilotBriefing ServiceBroker ...");
| run = Boolean.FALSE;
|
| logInfo("Interrupting polling thread ...");
| daemonThread.interrupt();
|
| if (session != null) {
| try {
| logInfo("Closing JMS Session ...");
| session.close();
| } catch (JMSException e) {
| log.error(e.getMessage(), e);
| }
| }
|
| if (connection != null) {
| try {
| logInfo("Closing JMS Connection ...");
| connection.close();
| } catch (JMSException e) {
| log.error(e.getMessage(), e);
| }
| }
|
| if (pool != null) {
| logInfo("Shutting down ThreadPool");
| pool.shutdownNow();
| }
|
| log.info("==== ServiceBroker shutdown complete");
| }
| }
|
| private void logInfo(String msg) {
| log.info(PREFIX + msg);
| }
|
| /**
| * Initialization of JMS environment.
| * @param _ctx external configuration parameters
| * @throws NamingException
| * @throws JMSException
| */
| private void initializeJMSEnvironment(ApplicationContext _ctx) throws NamingException, JMSException {
| Queue queue = (Queue) _ctx.getBean("requestQueue");
|
| logInfo("Lookup of ConnectionFactory ...");
| ConnectionFactory cf = (ConnectionFactory) _ctx.getBean("jmsConnectionFactory");
|
| logInfo("Creating JMS Connection ...");
| connection = cf.createConnection();
|
| logInfo("Creating JMS Session ...");
| session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
|
| logInfo("Creating MessagConsumer ...");
| consumer = session.createConsumer(queue);
| }
|
| /**
| * Setup a pool of worker threads for message handling.
| * @param _ctx external configuration parameters
| */
| private void initializeWorkerThreadPool(ApplicationContext _ctx) {
| int poolSize = (Integer) _ctx.getBean("threadPoolSize");
| logInfo("Initializing Thread Pool [#" + poolSize + "] ...");
| pool = Executors.newFixedThreadPool(poolSize);
| }
|
| /**
| * Daemon thread for the dispatching of incoming messages to a pooled Worker Thread that will handle the request.
| * This class is implemented as a Thread because otherwise the Servlet Container Thread that executes this listener class,
| * fails to complete as a result of the polling-loop.
| */
| class MessageDispatcher implements Runnable {
| public void run() {
| try {
| while (run) {
| TextMessage message = (TextMessage) consumer.receive();
| if (message != null) {
| JMSUtils.printMessage("Received request", message);
| pool.execute(createMessageHandler(message));
| }
| }
| } catch (Throwable t) {
| log.error(t.getMessage(), t);
| }
| }
|
| /**
| * Factory method.
| * @param message
| * @return
| * @throws JMSException
| */
| private Runnable createMessageHandler(TextMessage message) throws JMSException {
| return new MessageHandler(metService, session, message.getJMSReplyTo(), message.getJMSMessageID(), message.getText());
| }
|
| }
View the original post : http://www.jboss.org/index.html?module=bb&op=viewtopic&p=4257808#4257808
Reply to the post : http://www.jboss.org/index.html?module=bb&op=posting&mode=reply&p=4257808
15 years, 3 months