title: Getting out of memory error when restarting WildFly on OpenShift
body: <p>I have a issue with WildFly AS on OpenShift. When i try to deploy WAR on server i keep getting following exception.</p>
  
  <pre><code>2014-12-20 04:31:33,072 INFO  [org.jboss.as.connector.deployment] (MSC service thread 1-7) JBAS010406: Registered connection factory java:/JmsXA
  2014-12-20 04:31:33,444 ERROR [org.hornetq.core.client] (Thread-0 (HornetQ-client-global-threads-32821528)) HQ214017: Caught unexpected Throwable: java.lang.OutOfMemoryError: unable to create new native thread
          at java.lang.Thread.start0(Native Method) [rt.jar:1.8.0_05]
          at java.lang.Thread.start(Thread.java:714) [rt.jar:1.8.0_05]
          at java.util.concurrent.ThreadPoolExecutor.addWorker(ThreadPoolExecutor.java:950) [rt.jar:1.8.0_05]
          at java.util.concurrent.ThreadPoolExecutor.execute(ThreadPoolExecutor.java:1368) [rt.jar:1.8.0_05]
          at org.hornetq.core.client.impl.ClientSessionFactoryImpl$Channel0Handler.notifyTopologyChange(ClientSessionFactoryImpl.java:1618) [hornetq-core-client-2.4.5.Final.jar:]
          at org.hornetq.core.client.impl.ClientSessionFactoryImpl$Channel0Handler.handlePacket(ClientSessionFactoryImpl.java:1609) [hornetq-core-client-2.4.5.Final.jar:]
          at org.hornetq.core.protocol.core.impl.ChannelImpl.handlePacket(ChannelImpl.java:641) [hornetq-core-client-2.4.5.Final.jar:]
          at org.hornetq.core.protocol.core.impl.RemotingConnectionImpl.doBufferReceived(RemotingConnectionImpl.java:556) [hornetq-core-client-2.4.5.Final.jar:]
          at org.hornetq.core.protocol.core.impl.RemotingConnectionImpl.bufferReceived(RemotingConnectionImpl.java:532) [hornetq-core-client-2.4.5.Final.jar:]
          at org.hornetq.core.client.impl.ClientSessionFactoryImpl$DelegatingBufferHandler.bufferReceived(ClientSessionFactoryImpl.java:1712) [hornetq-core-client-2.4.5.Final.jar:]
          at org.hornetq.core.remoting.impl.invm.InVMConnection$1.run(InVMConnection.java:165) [hornetq-server-2.4.5.Final.jar:]
          at org.hornetq.utils.OrderedExecutorFactory$OrderedExecutor$1.run(OrderedExecutorFactory.java:104) [hornetq-core-client-2.4.5.Final.jar:]
          at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [rt.jar:1.8.0_05]
          at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [rt.jar:1.8.0_05]
          at java.lang.Thread.run(Thread.java:745) [rt.jar:1.8.0_05]
  </code></pre>
  
  <p>I don't know if its related but i think errors started when i added hibernate to my application. Here is the <code>hibernate.cfg.xml</code></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd"&gt;
  &lt;hibernate-configuration&gt;
      &lt;session-factory&gt;
  
          &lt;property name="hibernate.dialect"&gt;org.hibernate.dialect.MySQLDialect&lt;/property&gt;   
          &lt;property name="connection.datasource"&gt;java:comp/env/jdbc/MyDataSource&lt;/property&gt; 
          &lt;property name="hibernate.current_session_context_class"&gt;thread&lt;/property&gt;
  
          &lt;!-- GENERAL CONFIGURATION --&gt;
          &lt;property name="connection.pool_size"&gt;1&lt;/property&gt;
          &lt;property name="hibernate.show_sql"&gt;false&lt;/property&gt;
          &lt;property name="hibernate.connection.release_mode"&gt;after_statement&lt;/property&gt;
          &lt;property name="hibernate.connection.autocommit"&gt;false&lt;/property&gt;
          &lt;property name="hibernate.connection.defaultAutoCommit"&gt;false&lt;/property&gt;
  
          &lt;!-- DB MAPING --&gt;
  
      &lt;/session-factory&gt;
  &lt;/hibernate-configuration&gt;
  </code></pre>
  
  <p>My <code>HibernateUtil.java</code>:</p>
  
  <pre><code>import org.hibernate.SessionFactory;
  import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
  import org.hibernate.cfg.Configuration;
  import org.hibernate.service.ServiceRegistry;
  
  public class HibernateUtil {
      private static SessionFactory sessionFactory;
  
      public static SessionFactory getSessionFactory() {
  
          if (sessionFactory == null) {
              // loads configuration and mappings
              Configuration configuration = new Configuration().configure();
              ServiceRegistry serviceRegistry
                  = new StandardServiceRegistryBuilder()
                      .applySettings(configuration.getProperties()).build();
  
              // builds a session factory from the service registry
              sessionFactory = configuration.buildSessionFactory(serviceRegistry);           
          }
  
          return sessionFactory;
      }
  }
  </code></pre>
  
  <p>And part of my DaoImpl i'm using for login:</p>
  
  <pre><code>  public User login(String username, String password) {
  
          User result = null;
  
          Session session = HibernateUtil.getSessionFactory().openSession();
          try {
              String sql = "select s from User s where username=:username and password=password(:password)";
              Query query = session.createQuery(sql);
              query.setString("username", username);
              query.setString("password", password);
              result = (User) query.uniqueResult();
          }
          finally {
              session.close();
          }
  
          return result;
      }
  </code></pre>
  
  <p>I'm not 100% shure its problem with hibernate because i'we connected over SSH removed all in <code>wildfly/standalone/deployments/</code> and restarted app but i'm still getting floowing error when i execute <code>gear start</code> command.</p>
  
  <pre><code>2014-12-20 04:46:47,792 WARN  [org.hornetq.core.server] (hornetq-failure-check-thread) HQ222082: error on connection failure check: java.lang.OutOfMemoryError: unable to create new native thread
          at java.lang.Thread.start0(Native Method) [rt.jar:1.8.0_05]
          at java.lang.Thread.start(Thread.java:714) [rt.jar:1.8.0_05]
          at java.util.concurrent.ThreadPoolExecutor.addWorker(ThreadPoolExecutor.java:950) [rt.jar:1.8.0_05]
          at java.util.concurrent.ThreadPoolExecutor.execute(ThreadPoolExecutor.java:1357) [rt.jar:1.8.0_05]
          at org.hornetq.utils.OrderedExecutorFactory$OrderedExecutor.execute(OrderedExecutorFactory.java:133) [hornetq-core-client-2.4.5.Final.jar:]
          at org.hornetq.core.remoting.server.impl.RemotingServiceImpl$FailureCheckAndFlushThread.run(RemotingServiceImpl.java:739) [hornetq-server-2.4.5.Final.jar:]
  
  2014-12-20 04:46:48,674 ERROR [stderr] (Thread-0 (HornetQ-scheduled-threads-30017644)) Exception in thread "Thread-0 (HornetQ-scheduled-threads-30017644)" java.lang.OutOfMemoryError: unable to create new native thread
  2014-12-20 04:46:48,675 ERROR [stderr] (Thread-0 (HornetQ-scheduled-threads-30017644))  at java.lang.Thread.start0(Native Method)
  2014-12-20 04:46:48,675 ERROR [stderr] (Thread-0 (HornetQ-scheduled-threads-30017644))  at java.lang.Thread.start(Thread.java:714)
  2014-12-20 04:46:48,675 ERROR [stderr] (Thread-0 (HornetQ-scheduled-threads-30017644))  at java.util.concurrent.ThreadPoolExecutor.addWorker(ThreadPoolExecutor.java:950)
  2014-12-20 04:46:48,676 ERROR [stderr] (Thread-0 (HornetQ-scheduled-threads-30017644))  at java.util.concurrent.ThreadPoolExecutor.processWorkerExit(ThreadPoolExecutor.java:1018)
  2014-12-20 04:46:48,676 ERROR [stderr] (Thread-0 (HornetQ-scheduled-threads-30017644))  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1160)
  2014-12-20 04:46:48,676 ERROR [stderr] (Thread-0 (HornetQ-scheduled-threads-30017644))  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
  2014-12-20 04:46:48,677 ERROR [stderr] (Thread-0 (HornetQ-scheduled-threads-30017644))  at java.lang.Thread.run(Thread.java:745)
  2014-12-20 04:46:49,675 ERROR [stderr] (Thread-2 (HornetQ-scheduled-threads-30017644)) Exception in thread "Thread-2 (HornetQ-scheduled-threads-30017644)" java.lang.OutOfMemoryError: unable to create new native thread
  </code></pre>