AnsweredAssumed Answered

Concern about JavaDelegate implementations

Question asked by fwachs on Dec 5, 2012
Latest reply on Dec 7, 2012 by jbarrez
Hi all,

I haven't found any documentation or posts about what's the life cycle for the implementations of JavaDelegate.
I am worried about this because on my JavaDelegate implementations I create a database connection and use it normally, but i'm not sure what happens next with this instance, does it get crashed by the GC at some point? Does Activiti kill it somehow once the JavaDelegate has fulfilled it's purpose?

Talking about my java delegates itself, I am not closing those connections, I'm betting I should close them at the end of the execute method is done, am I betting correctly? :)

Regards and sorry for the newbie questions, I'm new to all this.


PD: Here are my classes, keep in mind they are just for testing purposes :)

public class UpdateSQLProcessTask extends SQLProcessTask {

    protected void executeSQL(DelegateExecution execution) {
        Properties props = new Properties();
        int rows = this.getTemplate().update(this.getSQL(execution));
        props.setProperty("rows", String.valueOf(rows));

public abstract class SQLProcessTask extends DataSourceTask implements JavaDelegate {
    protected FixedValue fixedSQL;
    protected JuelExpression expressionSQL;

    public void execute(DelegateExecution execution) {

    protected abstract void executeSQL(DelegateExecution execution);

    protected void closeDatasource() {
        try {
            DataSourceUtils.releaseConnection(this.datasource.getConnection(), this.datasource);
            this.datasource = null;
        } catch (SQLException e) {

    public void setFixedSQL(FixedValue fixedSQL) {
        this.fixedSQL = fixedSQL;

    public void setExpressionSQL(JuelExpression expressionSQL) {
        this.expressionSQL = expressionSQL;

    public String getSQL(DelegateExecution execution) {
        if (expressionSQL != null) {
            return expressionSQL.getValue(execution).toString();
        } else if (fixedSQL != null) {
            return fixedSQL.getValue(execution).toString();
        return null;

public class DataSourceTask {

    protected DataSource datasource = createDatasource();
    protected JdbcTemplate template = new JdbcTemplate(datasource);

    protected JdbcTemplate getTemplate() {
        return template;

    private DataSource createDatasource() {
        return new DriverManagerDataSource(
                "jdbc:mysql://someHost:3306/someDB", "user",