cancel
Showing results for 
Search instead for 
Did you mean: 

Thread LockException while navigation - on-Demand FileDownload

Amey-Mogare
Contributor
0 Kudos

Hi,

I am using FileDownload UI Element in table cell editor and I have implemented on demand file download feature using

1. IWDResource type of attribute

and

2. IWDInputStream (calculated-readOnly) type of context attribute

Now, this is working fine.

I have two views in my Web Dynpro application. View-1 is default view and contains just a link which fires plug to View-2.

This View-2 has a table with several on demand file download UI implemented as above.

Also, this View-2 has a "back" button which simply navigates back to View-1.

Now this is what is happening:-

1. Click on any "download" Ui element, a Open/Save As/Cancel pop up appears

2. If I click cancel and then click on "BacK" button, I get following dump:-


com.sap.tc.webdynpro.services.session.LockException: Thread SAPEngine_Application_Thread[impl:3]_8 
failed to acquire exclusive lock on client session ClientSession(id=(J2EE98155800)
ID0466322950DB11984004501243847285End_1160675775). 
Existing locks: LockingManager(ThreadName:SAPEngine_Application_Thread[impl:3]_8, 
exclusive client session lock: ClientSessionLock(SAPEngine_Application_Thread[impl:3]_37),
shared client session locks: ClientSessionSharedLockManager([]), 
app session locks: ApplicationSessionLockManager([]), 
current request: vendor.com/dp_genld/LdaApp).
Hint: Take a thread dump of the server node to find the blocking thread that causes the problem.

Note that, the weird thing is if I click cancel and then Back --> this dump occurs

And if I click Save As or Open and then then Back --> works fine

Can anybody please help me with this?

Thanks and regards,

Amey Mogare

Accepted Solutions (0)

Answers (2)

Answers (2)

Amey-Mogare
Contributor
0 Kudos

Its the limitation of file download UI element in Web Dynpro. Especially when you download huge files such as 1-2MB and larger.

former_member185086
Active Contributor
0 Kudos

Hi

Please go through SAP Note 1113811 , and tell us Is any database is coming during this download??

The reason of LockException may be different for different cases. The LockException itself means that your thread where the Web Dynpro application is running, is waiting for some other thread to complete it's operation. It can be because of synchronized methods used to access shared resource.

Debug could also help uin this ,you can find which thread is blocking your's this function/app

Best Regards

Satish Kumar

Amey-Mogare
Contributor
0 Kudos

Hi Satish,

Thank you for reply.

I am 100% sure that there aren't any database or RFC calls for this file download.

I have observed that for this type of on-demand download technique, Web Dynpro framework created a temporary inputstream or byte streams in J2EE engine's memory.

From this memory, the actual download takes place.

So what I have observed is tha, when I click on any download link in a table (say it contains 2MB of data), when a ALLOW SAVE pop up window appears, I click on "cancel" and proceed to any other click on view.

This is when the LockException occurs.

Note that if I keep 10 seconds of delay between these two clicks, there is no exception.

So is there any way I can code some delay once user clicks "Cancel" on this autogenerated popup window?

Thanks and regards,

Amey Mogare

former_member185086
Active Contributor
0 Kudos

Hi

Try using

WDFileDownloadBehaviour.OPEN_INPLACE.ordinal

in place of ALLOW SAVE

BR

Satish Kumar

Amey-Mogare
Contributor
0 Kudos

Hi Satish,

Thank you for reply.

Yes, I tried all three options :- ALLOW_SAVE, OPEN_INPLACE and AUTO.

But unfortunately, none of them helped.

This is how I coded the calculated attribute's getter method.

May be it will help you in locating what is going wrong here:-


  //@@begin javadoc:getCtx_vn_KmFolderDataFileStreamCalc(IPrivateTestFileUploadView.ICtx_vn_KmFolderDataElement)
  /**
   *  Declared getter method for attribute FileStreamCalc of node ctx_vn_KmFolderData
   *  @param element the element requested for the value
   *  @return the calculated value for attribute FileStreamCalc
   */
  //@@end
  public com.sap.tc.webdynpro.progmodel.api.IWDInputStream getCtx_vn_KmFolderDataFileStreamCalc(IPrivateTestFileUploadView.ICtx_vn_KmFolderDataElement element)
  {
    //@@begin getCtx_vn_KmFolderDataFileStreamCalc(IPrivateTestFileUploadView.ICtx_vn_KmFolderDataElement)
	IWDInputStream onDemandStream = null;
	String l_str_LinkValue = null;
	String l_str_LinkName = null;
	URL l_url = null; 
	InputStream  l_is_inputS = null; 
	try {
		l_str_LinkValue = element.getLinkValue();
		l_url = new URL(l_str_LinkValue);
		l_is_inputS = l_url.openStream();
		onDemandStream = WDResourceFactory.createInputStream(l_is_inputS);
	}
	catch (Exception e) {
		myMessage.reportException("Exception in getCtx_vn_KmFolderDataFileStreamCalc : "+e.toString(), true);
	}
	return onDemandStream;
    //@@end
  }

Any more ideas, help is badly needed and would be greatly appreciated.

Thanks and regards,

Amey Mogare

former_member185086
Active Contributor
0 Kudos

Hi

OK, try this , before this I would suggest try out this code from outside table and let see the result

byte[] chunk= wdContext.currentOutput_PrintInvoiceElement().getBinaryData();
// A binary data which is assigned to byte array , further can be used in IWDResource element

Now

if (window != null)
		{
			window.destroyInstance();
		}
		IWDResource resource= wdContext.currentGetPrintInvoiceDataElement().getBinaryData();
		window= wdComponentAPI.getWindowManager().createNonModalExternalWindow(resource.getUrl(WDFileDownloadBehaviour.OPEN_INPLACE.ordinal()), "Browser-description");
		window.removeWindowFeature(WDWindowFeature.ADDRESS_BAR);
		window.removeWindowFeature(WDWindowFeature.MENU_BAR);
		window.removeWindowFeature(WDWindowFeature.STATUS_BAR);
		window.removeWindowFeature(WDWindowFeature.TOOL_BAR);
		window.setWindowSize(780, 430);
		window.setWindowPosition(20, 140);
		window.show();

Modify it accordingly.

Best Regards

Satish Kumar

Amey-Mogare
Contributor
0 Kudos

Hi Satish,

Thank you for your continued help and guidance.

I coded according to your suggestion.

1. Created a button

2. Created a context attribute of type IWDWindow

Created a context attribute of type IWDResource

2. On click of the button, wrote this code:-


  //@@begin javadoc:onActionaDownloadSingle(ServerEvent)
  /** Declared validating event handler. */
  //@@end
  public void onActionaDownloadSingle(com.sap.tc.webdynpro.progmodel.api.IWDCustomEvent wdEvent )
  {
    //@@begin onActionaDownloadSingle(ServerEvent)
    IWDWindow window = wdContext.currentContextElement().getCtx_va_WindowInstance();
	IWDResource resource = wdContext.currentContextElement().getCtx_va_ResForKmFolderData1();
    try {
		if (window != null){
			window.destroyInstance();
		}
		if(resource != null){
			resource = null;
		}
		URL l_url = new URL(wdContext.currentContextElement().getLinkValue());
		InputStream l_is_inputS = l_url.openStream();
		resource = WDResourceFactory.createResource(l_is_inputS, "download", WDWebResourceType.UNKNOWN, true);
		wdContext.currentContextElement().setCtx_va_ResForKmFolderData1(resource);
		l_is_inputS.close();
		window = wdComponentAPI.getWindowManager().createNonModalExternalWindow(resource.getUrl(WDFileDownloadBehaviour.ALLOW_SAVE.ordinal()), "Browser-description");
		wdContext.currentContextElement().setCtx_va_WindowInstance(window);
		window.show();
	}
	catch (Exception e) {
		myMessage.reportException("Exception in onActionaDownloadSingle : "+e.toString(), false);
	}
    //@@end
  }

But while running, I am getting following error at browser:-


500   Internal Server Error SAP J2EE Engine/7.00  
The Web Dynpro Application 'UIapp' has expired. Restart the application using the Refresh button or via the following link UIapp. 

Any idea why this is happening?

Thanks and regards,

Amey Mogare

former_member185086
Active Contributor
0 Kudos

Hi

Have u tried any other simple application ?, Have u deal with any app expire time in visual admin.

Do one more check..

Create a application , defined it expire time manually .and run it , observed the result.

Best Regards

Satish Kumar

Amey-Mogare
Contributor
0 Kudos

Hi Satish,

Thank you for your reply.

1. Application Expiry Time

After your suggestion, I went through this thread

I have set the sap.Expiration time as 100 seconds.

I will observe the results with this now.

2. Separate File Download Element (not in table)

I tried this approach and tried to download file of size 9MB. Then too, same thing happened.

If I click, "cancel" on file download pop-up, application runs into ThreadLock Exception.

I took thread dumps and default trace at the moment of ThreadLockException, but not sure how to and what to look into thread dumps.

Thanks and regards,

Amey Mogare

Amey-Mogare
Contributor
0 Kudos

Hi Satish,

I did as you suggested and observed the result.

1. Application Expiry Time

After your suggestion, I went through this thread

I have set the sap.Expiration time as 420 seconds (7mins).

Observation : For larger files, application expires immediately within 1-2 seconds. (not main application window... the one which is opened as open/save as/cancel box)

2. Separate File Download Element (not in table)

I tried this approach and tried to download file of size 9MB. Then too, same thing happened.

If I click, "Cancel" on file download pop-up, application runs into ThreadLock Exception.

I took thread dumps and default trace at the moment of ThreadLockException. From thread dumps and default trace, what I understood is that File Download daemon is locking client session.

Is it so that when I Open/Save As/Cancel window opens up, it acquires lock on WD application thread (as WD is single threaded model) and when we click on cancel, relinquishing this lock takes time and ThreadLockException occurs??

Can we programmatically do something to avoid this?

Please help.

Thanks and regards,

Amey Mogare