Diese Seite (Version-1) wurde zuletzt am 28-März-2017 14:37 von Administrator geändert.

Du bist nicht autorisiert, diese Seite umzubenennen.

Du bist nicht autorisiert, diese Seite zu löschen.

Versionsgeschichte der Seite

Version Zuletzt geändert Größe Autor Änderungen Kommentar

Links

Eingehende Links Ausgehende Links

Versionsunterschiede

Unterschiede zwischen Version und .

Zeile 1: 273 Zeilen hinzugefügt.
[{ALLOW view All}]
[{ALLOW edit Authenticated}]
[{TableOfContents }]
!Update of TomEE to [7.02|http://tomee.apache.org/downloads.html]
{{{
wget http://repo.maven.apache.org/maven2/org/apache/tomee/apache-tomee/7.0.2/apache-tomee-7.0.2-webprofile.tar.gz
gunzip apache-tomee-7.0.2-webprofile.tar.gz
tar
}}}
!Tomcat init.d script
This one from [liferay|https://www.liferay.com/web/brett.swaim/blog/-/blogs/sample-tomcat-startup-scripts] seems to be quite ok.\\
See also [Init.d] | [Guide from mulesoft|https://www.mulesoft.com/tcat/tomcat-linux]
1. create a file /etc/init.d/<scriptname>:
{{{
#!/bin/bash
#
# tomcat This shell script takes care of starting and stopping Tomcat
#
# chkconfig: - 80 20
#
### BEGIN INIT INFO
# Provides: tomcat
# Required-Start: $network $syslog
# Required-Stop: $network $syslog
# Default-Start:
# Default-Stop:
# Short-Description: start and stop tomcat
### END INIT INFO
TOMCAT_USER=liferayapp
TOMCAT_HOME="/opt/liferay/tomcat-7.0.27"
SHUTDOWN_WAIT=45
tomcat_pid() {
echo `ps aux | grep org.apache.catalina.startup.Bootstrap | grep -v grep | awk '{ print $2 }'`
}
start() {
pid=$(tomcat_pid)
if [ -n "$pid" ]
then
echo "Tomcat is already running (pid: $pid)"
else
# Start tomcat
echo "Starting tomcat"
/bin/su - -c "cd $TOMCAT_HOME/bin && $TOMCAT_HOME/bin/startup.sh" $TOMCAT_USER
fi
return 0
}
stop() {
pid=$(tomcat_pid)
if [ -n "$pid" ]
then
echo "Stoping Tomcat"
/bin/su - -c "cd $TOMCAT_HOME/bin && $TOMCAT_HOME/bin/shutdown.sh" $TOMCAT_USER
let kwait=$SHUTDOWN_WAIT
count=0
count_by=5
until [ `ps -p $pid | grep -c $pid` = '0' ] || [ $count -gt $kwait ]
do
echo "Waiting for processes to exit. Timeout before we kill the pid: ${count}/${kwait}"
sleep $count_by
let count=$count+$count_by;
done
if [ $count -gt $kwait ]; then
echo "Killing processes which didn't stop after $SHUTDOWN_WAIT seconds"
kill -9 $pid
fi
else
echo "Tomcat is not running"
fi
return 0
}
case $1 in
start)
start
;;
stop)
stop
;;
restart)
stop
start
;;
status)
pid=$(tomcat_pid)
if [ -n "$pid" ]
then
echo "Tomcat is running with pid: $pid"
else
echo "Tomcat is not running"
fi
;;
esac
exit 0
}}}
2. Change ownerschip:
{{{
chmod 755 /etc/init.d/<scriptfile>
}}}
3. register in init.d
{{{
update-rc.d <scriptfile> defaults 80 20
}}}
! SQL setup and issues
In one of my webapps I had the problem, that a simple SQL query could not be executed anymore the next day after the server was started.
{{{
91156451 DatePlanner201_JPA TRACE [http-bio-80-exec-9] openjpa.Query - Executing query: [SELECT x FROM DateGroup x where x.clientId = ?1] with parameters: {0=0}
Jan 04, 2014 9:47:15 AM org.apache.geronimo.transaction.manager.TransactionImpl enlistResource
WARNING: Unable to enlist XAResource org.apache.openejb.resource.jdbc.managed.local.LocalXAResource@6822098c, errorCode: 0
javax.transaction.xa.XAException: Count not turn off auto commit for a XA transaction
at org.apache.openejb.resource.jdbc.managed.local.LocalXAResource.start(LocalXAResource.java:68)
at org.apache.geronimo.transaction.manager.TransactionImpl.enlistResource(TransactionImpl.java:209)
at org.apache.openejb.resource.jdbc.managed.local.ManagedConnection.invoke(ManagedConnection.java:111)
at com.sun.proxy.$Proxy130.prepareStatement(Unknown Source)
[...]
Caused by: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: The last packet successfully received from the server was 69.695.505 milliseconds ago.
The last packet sent successfully to the server was 69.695.505 milliseconds ago. is longer than the server configured value of 'wait_timeout'.
You should consider either expiring and/or testing connection validity before use in your application, increasing the server configured values for client timeouts,
or using the Connector/J connection property 'autoReconnect=true' to avoid this problem.
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
[...]
Caused by: java.net.SocketException: Broken pipe
at java.net.SocketOutputStream.socketWrite0(Native Method)
[...]
Jan 04, 2014 9:47:15 AM org.apache.openejb.core.transaction.EjbTransactionUtil handleSystemException
SEVERE: EjbTransactionUtil.handleSystemException: Failed to execute query "SELECT x FROM DateGroup x where x.clientId = ?1". Check the query syntax for correctness.
See nested exception for details.
<openjpa-2.3.0-nonfinal-1540826-r422266:1542644 nonfatal user error> org.apache.openjpa.persistence.ArgumentException: Failed to execute query
"SELECT x FROM DateGroup x where x.clientId = ?1". Check the query syntax for correctness. See nested exception for details.
at org.apache.openjpa.kernel.QueryImpl.execute(QueryImpl.java:872)
[...]
Caused by: java.lang.reflect.UndeclaredThrowableException
at com.sun.proxy.$Proxy130.prepareStatement(Unknown Source)
[...]
Caused by: javax.transaction.RollbackException: Transaction is marked for rollback
at org.apache.geronimo.transaction.manager.TransactionImpl.registerSynchronization(TransactionImpl.java:154)
}}}
{{{
Caused by: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: The last packet successfully received from
the server was 41.371.723 milliseconds ago. The last packet sent successfully to the server was
41.371.723 milliseconds ago. is longer than the server configured value of 'wait_timeout'.
You should consider either expiring and/or testing connection validity before use in your application,
increasing the server configured values for client timeouts, or using the Connector/J connection property
'autoReconnect=true' to avoid this problem.
}}}
Maybe it is due to this [MySQL problem|http://dev.mysql.com/doc/refman/5.1/de/connector-j-usagenotes-troubleshooting.html#qandaitem-25-3-5-3-1-4]. => autoReconnect=true (?)
Tried also the option "defaultAutoCommit = false"
and now additionally
autoReconnectForPools=true.
Tomcat uses by default the transaction manager from [Apache Commons DBCP|http://tomcat.apache.org/tomcat-7.0-doc/jdbc-pool.html]. But there is obviously a better one, see Tomcat docu. You can set it with the "factory" entry.
This is my <tomee>/conf/tomee.xml now\\
Docu: [Containers & Resources|http://tomee.apache.org/containers-and-resources.html] | Docu: [DataSource Configuration|http://tomee.apache.org/datasource-config.html] | Docu: [Transaction Manager|http://tomee.apache.org/transactionmanager-config.html] | [JDBC Pool Sizing|http://www.tomcatexpert.com/blog/2010/04/01/configuring-jdbc-pool-high-concurrency] | Docu: [MySql Properties|http://dev.mysql.com/doc/refman/5.1/de/connector-j-reference-configuration-properties.html] | Docu: [MySQL Server Variables|http://dev.mysql.com/doc/refman/5.0/en/server-system-variables.html]
{{{
<?xml version="1.0" encoding="UTF-8"?>
<tomee>
<Resource id="dp_Database" type="javax.sql.DataSource">
factory = org.apache.tomcat.jdbc.pool.DataSourceFactory
jdbcDriver = com.mysql.jdbc.Driver
jdbcUrl = jdbc:mysql://localhost:3306/dp
connectionProperties = [autoReconnect=true,autoReconnectForPools=true]
defaultAutoCommit = false
userName = myuser
password = mypassword
poolPreparedStatements = true
jtaManaged = true
testOnBorrow = true
validationQuery = SELECT 1
validationInterval = 30000
</Resource>
<!-- not used anymore:
<Resource id="dp_DatabaseUnmanaged" type="javax.sql.DataSource">
jdbcDriver = com.mysql.jdbc.Driver
jdbcUrl = jdbc:mysql://localhost:3306/dp?autoReconnect=true
connectionProperties = [autoReconnect=true,autoReconnectForPools=true]
userName = myuser
password = mypassword
poolPreparedStatements = true
jtaManaged = false
</Resource>
-->
</tomee>
}}}
NOTE: If you do not specify a unmanaged datasource (jta=false), then Tomcat seems to create default one, see <tom>/logs/catalina.out!
The relation to the persistence.xml is
{{{
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0"
xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
<persistence-unit name="DatePlanner201_JPA">
<description>dp</description>
<provider>org.apache.openjpa.persistence.PersistenceProviderImpl</provider>
<jta-data-source>java:openejb/Resource/dp_Database</jta-data-source>
<!-- not used anymore
<non-jta-data-source>java:openejb/Resource/dp_DatabaseUnmanaged</non-jta-data-source>
-->
[...]
}}}
There are also some parameters in MySQL directly, called server variables. If you connect to mysql you can use
{{{
> SHOW VARIABLES;
==> wait_timeout 28800sec = 8h
> set WAIT_TIMEOUT = ...;
}}}
This was also a hint:\\
Also, make sure to set the following property on the MySQL datasource:
{{{
pinGlobalTxToPhysicalConnection="true"
}}}
----
I noticed another execption in the log.
{{{
387603 DatePlanner201_JPA INFO [http-bio-80-exec-7] openjpa.Runtime - Starting OpenJPA 2.2.2
387749 DatePlanner201_JPA INFO [http-bio-80-exec-7] openjpa.jdbc.JDBC - Using dictionary class "org.apache.openjpa.jdbc.sql.MySQLDictionary" (MySQL 5.1.72-0ubuntu0.10.04.1 ,MySQL Connector Java mysql-connector-java-5.1.27 ( Revision: alexander.soklakov@oracle.com-20131021093118-gtm1bh1vb450xipt )).
387993 DatePlanner201_JPA WARN [http-bio-80-exec-7] openjpa.Enhance - An exception was thrown while attempting to perform class file transformation on "ebel.dp201.jpa.PropValueId":java.lang.NoClassDefFoundError: org/objectweb/asm/ClassVisitor
at org.apache.openjpa.enhance.PCClassFileTransformer.transform0(PCClassFileTransformer.java:156)
at org.apache.openjpa.enhance.PCClassFileTransformer.transform(PCClassFileTransformer.java:126)
at org.apache.openjpa.persistence.PersistenceProviderImpl$ClassTransformerImpl.transform(PersistenceProviderImpl.java:290)
at org.apache.openejb.persistence.PersistenceUnitInfoImpl$PersistenceClassFileTransformer.transform(PersistenceUnitInfoImpl.java:324)
[...]
}}}
This should be solved with a new OpenJPA version, see [here|https://issues.apache.org/jira/browse/OPENJPA-1676]\\
So I replaced the original jar file shipped with TomEE 1.6 Webprofile
{{{
<tomee>/lib/openjpa-2.3.0-nonfinal-1540826.jar
}}}
with the [nightly built|https://repository.apache.org/content/groups/snapshots/org/apache/openjpa/apache-openjpa/2.4.0-SNAPSHOT/]
{{{
<tomee>/lib/openjpa-2.4.0-20131106.135303-5.jar
}}}
----
Note: The currently stable version openjpa-2.2.2.jar does not work with TomEE.
You may receive following error:
{{{
Jan 04, 2014 11:59:49 AM org.apache.geronimo.transaction.manager.TransactionImpl beforeCompletion
WARNING: Unexpected exception from beforeCompletion; transaction will roll back
<openjpa-2.2.2-r422266:1468616 nonfatal general error> org.apache.openjpa.persistence.PersistenceException: null
at org.apache.openjpa.kernel.BrokerImpl.beforeCompletion(BrokerImpl.java:2008)
at org.apache.geronimo.transaction.manager.TransactionImpl.beforeCompletion(TransactionImpl.java:527)
[...]
Caused by: java.util.ConcurrentModificationException
at java.util.HashMap$HashIterator.nextEntry(HashMap.java:926)
}}}