Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Threads do not stop after reuploading v. 2 plugin, OSGi issue

sjaanus June 11, 2013

I have a plugin, which has thread pool sized 5 threads. The threads stay in an array and whenever the array is empty, I create 5 new threads and put them in the array.

Now I have a problem, that when I reupload plugin, the threads keep running, but the array will have 0 threads in there. So each time I reupload plugin, 5 new threads will start running and check the queue for a job.
In a short time after few reuploads of plugin, I will have too many pointless threads running.

Is there a somekind of Jira's OSGi lifecycle API, that if the plugin is being removed(reuploaded), I can listen to that event and stop the old threads. The normal OSGi has this functionality, and since you use Felix+OSGi, you should also have something similar.

EDIT:

I am using hibernate in my pom.xml.

<dependency>
			<groupId>org.hibernate</groupId>
			<artifactId>hibernate-core</artifactId>
			<version>4.1.6.Final</version>
		</dependency>

After using my own BundleActivator, I get error:

2013-06-12 13:57:15,572 Thread-54 ERROR sellinjaanus 904x1413x1 1lhku79 192.168.54.111 /secure/IssueAction.jspa [osgi.container.felix.FelixOsgiContainerManager] JarContent: Unable to read bytes.
java.lang.IllegalStateException: zip file closed
	at java.util.zip.ZipFile.ensureOpen(ZipFile.java:415)
	at java.util.zip.ZipFile.getEntry(ZipFile.java:160)
	at java.util.jar.JarFile.getEntry(JarFile.java:208)
	at org.apache.felix.framework.util.JarFileX.getEntry(JarFileX.java:61)
	at org.apache.felix.framework.cache.JarContent.getEntryAsBytes(JarContent.java:120)
	at org.apache.felix.framework.ModuleImpl$ModuleClassLoader.findClass(ModuleImpl.java:1738)
	at org.apache.felix.framework.ModuleImpl.findClassOrResourceByDelegation(ModuleImpl.java:716)
	at org.apache.felix.framework.ModuleImpl.access$200(ModuleImpl.java:73)
	at org.apache.felix.framework.ModuleImpl$ModuleClassLoader.loadClass(ModuleImpl.java:1690)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
	at org.hibernate.id.AbstractPostInsertGenerator.generate(AbstractPostInsertGenerator.java:40)
	at org.hibernate.event.internal.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:118)
	at org.hibernate.event.internal.DefaultMergeEventListener.saveTransientEntity(DefaultMergeEventListener.java:236)
	at org.hibernate.event.internal.DefaultMergeEventListener.entityIsTransient(DefaultMergeEventListener.java:216)
	at org.hibernate.event.internal.DefaultMergeEventListener.onMerge(DefaultMergeEventListener.java:154)
	at org.hibernate.event.internal.DefaultMergeEventListener.onMerge(DefaultMergeEventListener.java:76)
	at org.hibernate.internal.SessionImpl.fireMerge(SessionImpl.java:904)
	at org.hibernate.internal.SessionImpl.merge(SessionImpl.java:888)
	at org.hibernate.internal.SessionImpl.merge(SessionImpl.java:892)
	at com.tech.jira.hibernate.GenericDao.merge(GenericDao.java:77)
	at com.tech.jira.hibernate.ExternalController.merge(ExternalController.java:34)
	at com.tech.jira.ssrs.threads.SrssJob.createIssue(SrssJob.java:48)
	at com.tech.jira.ssrs.threads.SrssJob.execute(SrssJob.java:273)
	at com.tech.jira.ssrs.threads.Worker.run(Worker.java:23)
	at java.lang.Thread.run(Thread.java:662)

1 answer

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

1 vote
Answer accepted
Radu Dumitriu
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 11, 2013

I do not have this problem, so you must do something wrong.

See: http://www.osgi.org/javadoc/r4v43/core/org/osgi/framework/BundleActivator.html

But you have to register this into your OSGI

sjaanus June 11, 2013

Thanks, this seems promising.

When developing jira plugin I have never used bundleactivator, can you point me into direction, where should I add it into my code or such?

Radu Dumitriu
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 11, 2013

https://github.com/rdumitriu/jira-qanda/blob/master/pom.xml

<instructions>
<Bundle-Activator>ro.agrade.jira.qanda.plugin.PluginBundleActivator</Bundle-Activator>
</instructions>
Have fun, R

sjaanus June 11, 2013

Do I still compile with atlas-package ? Since I tried, but it didnt use my BundleActivator on plugin upload. I was using your POM from here though, I try with this new POM. https://answers.atlassian.com/questions/6374/how-do-i-access-jndi-from-a-version-2-osgi-plugin

sjaanus June 11, 2013

Ok it worked nice, now If i want to add external library, I just add it to the instructions there? or it must be osgi type library? whats the difference between obr file and jar file there?

sjaanus June 11, 2013

I tried uploading obr file or jar file, weird it doesnt run into my bundleactivator, which just prints out "hello world"

Radu Dumitriu
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 11, 2013

OBR is a package which contain bundling instructions + (optional) other jars. Specification allows you to specify index, environment, requirements for resolving other packages and bundles, etc.

Yes, check the bundling instructions, you can add dependencies as well.

sjaanus June 11, 2013

I ran into a issue with my own BundleActivator. Look the original edited post. Maybe you can help me.

Radu Dumitriu
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 13, 2013
Radu Dumitriu
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 13, 2013

Next time, open another question, pls, I've seen just by luck that you changed it. Besides, there are many users outthere, some of them may be better than me :)

TAGS
AUG Leaders

Atlassian Community Events