Win a copy of Five Lines of Code this week in the OO, Patterns, UML and Refactoring forum!
    Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Auto Publishing

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Report post to moderator
Hi,

I'm using RAD7.0 and the integrated websphere instance in it "WebSphere v6.1 Server". Once I change a java file in my j2ee project , I'll have to copy paste the .class file into the ear folder which is in the path ".metadata\.plugins\org.eclipse.wst.server.core\tmp0". I believe there should be some setting which should enable me to have this done automatically and the application restarting automatically. Help in this will be appreciated.

Thanks.
 
Ranch Hand
Posts: 598
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Report post to moderator
I so everything using server view. That is very comfortable and it does most of the task by itself.
 
Jazib Raza
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Report post to moderator
Hi Himanshu,

I'm not sure about the server view you are talking abou, could you please brief me about that. I'm sure there is some setting in RAD/WS to achive the above said , If any one has done this please share it.

Thanks,
Aslam
 
Himanshu Gupta
Ranch Hand
Posts: 598
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Report post to moderator
Go to windows-->show view-->servers
 
Marshal
Posts: 25669
69
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Report post to moderator
And to run a J2EE application, you just right-click the project and select "Run on Server". Choose one of the servers you have configured in the server view and everything happens automatically. No need to copy and paste anything.
 
Jazib Raza
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Report post to moderator
Hi All,

Thanks for your pointers on this. The issue I had was with the RAD version which I was using. It was RAD 7.0.0 and once I upgraded it to RAD 7.0.0.3 autopublish is working .
 
Jazib Raza
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Report post to moderator


import org.jsoup.Jsoup;
import org.jsoup.helper.Validate;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

import java.io.*;

/**
* Parse.
*/
public class ParseiXblr {
public static void main(String[] args) throws IOException {
final String companyName = "EntityCurrentLegalOrRegisteredName";
final String registeredNumber = "UKCompaniesHouseRegisteredNumber";
final String entityTrading = "EntityTrading";
final String entityDormant = "EntityDormant";
final String nameDirector = "NameDirectorSigningAccounts";
final String cashBankInHand = "CashBankInHand";

File input = new File("11.html");

BufferedReader br = new BufferedReader(new FileReader(input));
String line;
int compNameCount = 0;
int regNumberCount = 0;
String recordYearCashBank = null;
String recordYearCashBankLine = null;
while ((line = br.readLine()) != null) {
// process the line.
if(line.indexOf(companyName) != -1){
if(compNameCount>0){
continue;
}else {
System.out.println("Company Name");
parse(line);
compNameCount++;
}

}
if(line.indexOf(registeredNumber) != -1){
if(regNumberCount>0){
continue;
}else {
System.out.println("Registered Number");
parse(line);
regNumberCount++;
}
}
if(line.indexOf(entityTrading) != -1){
System.out.println("Entity Trading");
parse(line);
}
if(line.indexOf(entityDormant) != -1){
System.out.println("Entity Dormant");
parse(line);
}
if(line.indexOf(nameDirector) != -1){
System.out.println("Name Director");
parse(line);
}
if(line.indexOf(cashBankInHand) != -1){
if(recordYearCashBank != null){
String recordYearTemp = line.substring(line.indexOf("cfwd")+11, line.indexOf("cfwd")+15);
if(Integer.parseInt(recordYearTemp) > Integer.parseInt(recordYearCashBank)){
recordYearCashBankLine = line;
recordYearCashBank = recordYearTemp;
}
}else{
recordYearCashBank = line.substring(line.indexOf("cfwd")+11, line.indexOf("cfwd")+15);
recordYearCashBankLine = line;
}
}
}
System.out.println("CashBank In Hand");
parse(recordYearCashBankLine);
}
public static void parse(String line){
Document doc = Jsoup.parse(line);
System.out.println(doc.text());
}
}

 
Bartender
Posts: 1268
39
IBM DB2 Netbeans IDE Spring Java
  • Mark post as helpful
  • send pies
  • Report post to moderator

Jazib Raza wrote:Hi All,

Thanks for your pointers on this. The issue I had was with the RAD version which I was using. It was RAD 7.0.0 and once I upgraded it to RAD 7.0.0.3 autopublish is working .



Uhm. On server view, try and add your EAR project to target server. Please be sure you did not disable "publish automatically" option. Every time you modify your project, it is automatically published.
 
Jazib Raza
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Report post to moderator


<html>
<head>

</head>

<body bgcolor="#FFFFFF">





<!-- Include UltraGrid Enumerations-->
<SCRIPT language="VBScript" src="UltraGridEnums.vbs"></SCRIPT>
<SCRIPT language="VBScript" src="UltraGridConstants.inc"></SCRIPT>
<!-- Include common functions -->
<SCRIPT language="VBScript" src="dataUtils.inc"></SCRIPT>
<SCRIPT ID="clientEventHandlersVBS" LANGUAGE="vbscript">
<!--
option explicit
Dim oRS0 ' ADO Recordset
Set oRS0 = CreateObject("ADODB.Recordset")














Sub window_onload
CreateRecordsetInMemory_0
Set gridControl0.DataSource = oRS0
End Sub

Private Sub CreateRecordsetInMemory_0
' level 0 variables
Dim arrGRID_EVENT_ID0_0
Dim arrcustomerName0_0
Dim arrfederalId0_0
Dim arrcustAccountRelText0_0
Dim arrcrfType0_0
Dim arrcustId0_0
Dim arrbankruptcyStatusText0_0

arrGRID_EVENT_ID0_0 = Array(0, 1, 2, 3, 4)
arrbankruptcyStatusText0_0 = Array(null, null, null, null, null)
arrcrfType0_0 = Array("I", "I", "I", "I", "I")
arrcustAccountRelText0_0 = Array("One", "Two", "Three", "Four", "five")
arrcustId0_0 = Array("1", "2", "3", "4", "5")
arrcustomerName0_0 = Array("ABC", "ABC", "ABC", "ABC", "ABC")


oRS0.ActiveConnection = "provider=msdatashape;data provider=none;"

Dim strShape
strShape = _
"SHAPE APPEND New adInteger As 'GRID_EVENT_ID', " & _
"New adLongVarWChar As 'Name', " & _
"New adLongVarWChar As 'TIN', " & _
"New adLongVarWChar As 'Relationship', " & _
"New adLongVarWChar As 'CustomerType', " & _
"New adLongVarWChar As 'CustomerId', " & _
"New adLongVarWChar As 'Comments'"


oRS0.Open strShape, ,adOpenStatic, adLockOptimistic

If oRS0.State = adStateOpen And UBound(arrGRID_EVENT_ID0_0) >= 0 Then
Dim iFld
Dim iRow

For iRow = 0 to UBound(arrGRID_EVENT_ID0_0)
oRS0.AddNew
For iFld = 0 to oRS0.Fields.Count - 1
Select Case oRS0.Fields(iFld).Name
Case "GRID_EVENT_ID"
oRS0.Fields(iFld).value = arrGRID_EVENT_ID0_0(iRow)
Case "Name"
oRS0.Fields(iFld).value = arrcustomerName0_0(iRow)
Case "TIN"
'oRS0.Fields(iFld).value = arrfederalId0_0(iRow)
Case "Relationship"
oRS0.Fields(iFld).value = arrcustAccountRelText0_0(iRow)
Case "CustomerType"
oRS0.Fields(iFld).value = arrcrfType0_0(iRow)
Case "CustomerId"
oRS0.Fields(iFld).value = arrcustId0_0(iRow)
Case "Comments"
oRS0.Fields(iFld).value = arrbankruptcyStatusText0_0(iRow)
End Select
Next
oRS0.Update
Next
If UBound(arrGRID_EVENT_ID0_0) > 0 Then
oRS0.UpdateBatch
oRS0.MoveFirst
End If

End If
End Sub

Sub gridControl0_InitializeLayout(Context, Layout)

gridControl0.ViewStyle = ssViewStyleMultiBand
gridControl0.ViewStyleBand = ssViewStyleBandVertical
gridControl0.Override.ExpandRowsOnLoad = ssExpandOnLoadNo
'prevent painting while changes are being made
gridControl0.Redraw = False
gridControl0.Font.Name = "Verdana"
gridControl0.Appearance.BackColor = vbWhite
gridControl0.RowScrollRegions(0).Scrollbar = ssScrollBarShowIfNeeded
gridControl0.ColScrollRegions(0).Scrollbar = ssScrollBarShowIfNeeded
'create an appearance object used to highlight the header of the activecell's column
With Layout.Appearances.Add("Activated")
.BackColor = vbBlack
.ForeColor = RGB(255, 255, 220)
End With
With gridControl0.Override
.RowSelectors = ssRowSelectorsOff ' hide row selectors
.BorderStyleCell = ssBorderStyleNone ' hide grid lines
.BorderStyleRow = ssBorderStyleNone ' hide grid lines
.RowAppearance.BackColor = vbWhite ' alternate row color
.RowAlternateAppearance.BackColor = RGB(245,245,245)
.AllowGroupSwapping = ssAllowGroupSwappingNotAllowed
.AllowGroupMoving = ssAllowGroupMovingNotAllowed
.AllowColSwapping = ssAllowColSwappingNotAllowed
.AllowColMoving = ssAllowColMovingNotAllowed
.AllowDelete = ssAllowDeleteNo
.AllowUpdate = ssAllowUpdateNo
.AllowAddNew = ssAllowAddNewNo
End With

With gridControl0.Bands(0)
.columns("Name").CellAppearance.TextAlign = ssAlignLeft
.columns("Name").CellAppearance.TextVAlign = ssVAlignTop
.columns("TIN").CellAppearance.TextAlign = ssAlignLeft
.columns("TIN").CellAppearance.TextVAlign = ssVAlignTop
.columns("Relationship").CellAppearance.TextAlign = ssAlignLeft
.columns("Relationship").CellAppearance.TextVAlign = ssVAlignTop
.columns("CustomerType").CellAppearance.TextAlign = ssAlignLeft
.columns("CustomerType").CellAppearance.TextVAlign = ssVAlignTop
.columns("CustomerId").CellAppearance.TextAlign = ssAlignLeft
.columns("CustomerId").CellAppearance.TextVAlign = ssVAlignTop
.columns("Comments").CellAppearance.TextAlign = ssAlignLeft
.columns("Comments").CellAppearance.TextVAlign = ssVAlignTop
End With
With Layout.Bands(0)
.Override.CellAppearance.Font.Size = 8
.Override.HeaderClickAction = ssHeaderClickActionSortSingle
.Override.HeaderAppearance.BackColor = gHeaderBackColor 'yellow RGB(253,253,239)
.Override.HeaderAppearance.Font.Size = 9
.Override.HeaderAppearance.Font.Bold = gHeaderFontBold
.Override.HeaderAppearance.ForeColor = gHeaderForeColor
.Override.HeaderAppearance.TextAlign = ssAlignCenter
.Override.HeaderAppearance.TextVAlign = ssVAlignBottom
.ColHeaderLines = 1
.Columns("Name").Width = 260
.Columns("TIN").Width = 100
.Columns("Relationship").Width = 180
.Columns("CustomerType").Width = 180
.Columns("CustomerType").hidden = true
.Columns("CustomerId").Width = 180
.Columns("CustomerId").hidden = true
.Columns("Comments").Width = 180
.Columns("GRID_EVENT_ID").hidden = true
gridControl0.Redraw = True
End With

End Sub




Sub cboColumnStyle_onchange
'combo controls which column is displayed
With gridControl0
'scroll the column into view
.ActiveColScrollRegion.ScrollColumnIntoView .Bands(0).Columns(cboColumnStyle.Value), True

If Not .ActiveRow Is Nothing Then
'if there is an activerow then activate the cell from this column
Set .ActiveCell = .ActiveRow.Cells(cboColumnStyle.Value)
End If

'give the grid focus
.Focus
End With
End Sub




Private Sub gridControl0_ClickCellButton(Cell)
'msgbox "ClickCellButton Fired for " & Cell.Column.DataField, vbOKOnly, "Column Styles"
End Sub




Private Sub gridControl0_BeforeCellActivate(Cell, Cancel)
HighlightColumn True, Cell.Column
End Sub




Private Sub gridControl0_BeforeCellDeactivate(Cancel)
HighlightColumn False, gridControl0.ActiveCell.Column
End Sub




Private Sub HighlightColumn(Activated, Column)
If Activated Then
Column.Header.Appearance = "Activated"
Else
Column.Header.Appearance = ""
End If
End Sub




Private Sub gridControl0_BeforeCellActivate(Cell, Cancel)
HighlightColumn True, Cell.Column
Dim relativeUrl, name, tin, customerId

'
' This event fires when a grid cell is clicked.
' If the column clicked is Name column,
' then make the getCustomer call
'
if (Cell.Column.Key = "Name") then
name = gridControl0.ActiveRow.Cells("Name").Value
tin = gridControl0.ActiveRow.Cells("TIN").Value
if isNULL(tin) or tin = "" then
tin = ""
else
tin = replace(tin,"*","")
tin = replace(tin,"-","")
end if
customerId = gridControl0.ActiveRow.Cells("CustomerId").Value
'relativeUrl = "/prepareECIFAccountProfileAction.do?customerId=" & customerId & "&name=" &name & "&ssn=" &tin
relativeUrl = "test.html"
onHyperlinkClick(relativeUrl)
end if
End Sub

Private Sub gridControl0_AfterCellActivate()
' deactivate the active row so that the same link will be clickable again
gridControl0.ActiveCell = Nothing
End Sub

Sub gridControl0_InitializeRow(Context, Row, ReInitialize)

' as each row is displayed by the grid, this event is fired
' so we can dynamically control the row appearance

Row.Cells("Name").Appearance.Font.Underline = True
Row.Cells("Name").Appearance.Font.Name = "Verdana"
Row.Cells("Name").Appearance.Font.Size = 8
Row.Cells("Name").Appearance.ForeColor = RGB(0,0,255)

End Sub

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Private Sub gridControl0_MouseEnter(uiElement)
dim oCell, oColumn
If uiElement.Type = ssUIElementCell Then
Set oCell = uiElement.Cell
Set oColumn = oCell.Column
If oColumn.DataField = "Name" AND oCell.Appearance.Font.Underline = True Then
oCell.Appearance.MousePointer = ssHand
End If
End If
End Sub

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Private Sub gridControl0_MouseExit(uiElement)
dim oCell, oColumn
If uiElement.Type = ssUIElementCell Then
Set oCell = uiElement.Cell
Set oColumn = oCell.Column
If oColumn.DataField = "Name" Then
oCell.Appearance.MousePointer = ssDefault
End If
End If
End Sub
-->
</SCRIPT>

<script language="JavaScript">
function onHyperlinkClick(url) {
alert("Hi"+url);
window.location.href = url;
}
</script>



<OBJECT CLASSID="clsid:5220cb21-c88d-11cf-b347-00aa00a28331" id="Microsoft_Licensed_Class_Manager_1_0"> <PARAM NAME="LPKPath" VALUE="Ultragrid20.lpk"> </OBJECT> <OBJECT id=gridControl0 codebase="IGUltraGrid20.cab" style="null" height=360 width=760 classid="clsid:B3014671-7872-4671-BE73-5D05EB5B2AF5"> <PARAM NAME="_ExtentX" VALUE="16880"><PARAM NAME="_ExtentY" VALUE="9790"><PARAM NAME="_Version" VALUE="131072"><PARAM NAME="GridFlags" VALUE="17040384"><PARAM NAME="LayoutFlags" VALUE="4"><PARAM NAME="RowConnectorColor" VALUE="-2147483632"><PARAM NAME="EstimatedRows" VALUE="0"><PARAM NAME="TipDelay" VALUE="-1"><PARAM NAME="MaxColScrollRegions" VALUE="50"><PARAM NAME="MaxRowScrollRegions" VALUE="50"><PARAM NAME="BorderStyle" VALUE="0"><PARAM NAME="ScrollBars" VALUE="4"><PARAM NAME="RowConnectorStyle" VALUE="0"><PARAM NAME="TabNavigation" VALUE="0"><PARAM NAME="ViewStyle" VALUE="0"><PARAM NAME="ViewStyleBand" VALUE="0"><PARAM NAME="BorderStyleCaption" VALUE="0"><PARAM NAME="InterBandSpacing" VALUE="60"><PARAM NAME="AlphaBlendEnabled" VALUE="-1"><PARAM NAME="Enabled" VALUE="-1"><PARAM NAME="OLEDropMode" VALUE="0"> </OBJECT>


</body>


</html>
 
Jazib Raza
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Report post to moderator
import java.util.List;
import java.util.Map;
import java.util.Scanner;
import java.util.concurrent.Callable;
import java.util.concurrent.CompletionService;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorCompletionService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.ThreadPoolExecutor;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

public class GoogleSearchJava {

public static final String GOOGLE_SEARCH_URL = "https://www.google.com/search";
public static final String USER_AGENT = "Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; rv:11.0) like Gecko";
/*public static final String USER_AGENT = "Mozilla/5.0";*/
public static final List<String> searchResults = new ArrayList<String>(); // search result links
public static final int SUB_LIST_LIMIT = 10;
public static Map<String, Integer> jsLibraryList = new HashMap<String, Integer>(); // <js library, count>


public static void main(String[] args) throws IOException {
               //For Multi-Threading
               //Inner-class to implement threads
               class ThreadTask implements Callable<List<String>>{
                               private List<String> resultUrls =  new ArrayList<String>();
                               public ThreadTask(List<String> resultUrls) {
                                               //super();
                                               this.resultUrls = resultUrls;
                               }
                               @Override
                               public List<String> call() throws Exception {
                                               return parseAndGetJSLibraries();
                               }
                               private List<String> parseAndGetJSLibraries()
                                                               throws IOException {
                               List<String> jsLibraries =  new ArrayList<String>();
                               for(String result : resultUrls){
                                               Document doc = Jsoup.connect(result).userAgent(USER_AGENT).timeout(20*1000).get();
                                               // get the script tag elements
                                               Elements jsLibrary = doc.select("script[src$=.js]");
                                               for(Element lib : jsLibrary){
                                                               // parse the js libraries
                                                               jsLibraries.add(lib.attr("src"));
                                               }
                               }
                                               return jsLibraries;
                               }
                               
               }
               List<String> resultUrls = new ArrayList<String>();
               List<String> allJsLibraries = new ArrayList<String>();
              /* final String USER_AGENT = "Mozilla/5.0";*/
               //Taking search term input from console
               Scanner scanner = new Scanner(System.in);
               System.out.println("Please enter the search term.");
               String searchTerm = scanner.nextLine();
               System.out.println("Please enter the number of results. Example: 5 10 20");
               int num = scanner.nextInt();
               scanner.close();
               
               String searchURL = GOOGLE_SEARCH_URL + "?q="+searchTerm+"&num="+num;
              /* System.setProperty("http.proxyHost", "127.0.0.1");
               System.setProperty("http.proxyPort", "8182");
               Document doc = Jsoup.connect("https://stackoverflow.com";).get();
               System.out.println("Obtained Title: " + doc.title());*/

               //without proper User-Agent, we will get 403 error
               Document doc = Jsoup.connect(searchURL).userAgent(USER_AGENT).timeout(2*1000).get();
               //below will print HTML data, save it to a file and open in browser to compare
               //System.out.println(doc.html());
               
               //If google search results HTML change the <h3 class="r" to ><h3 class="r1" >
               //we need to change below accordingly
               Elements results = doc.select("h3.r > a");

               for (Element result : results) {
                   // Add into a list
                   String linkHref = result.attr("href");                                
                   System.out.println("URL::" + linkHref.substring(6, linkHref.indexOf("&")));
                   resultUrls.add(linkHref);
               }
                                                               
               // Iterate the list for each link
                                                               // Parse and find out javascript library in each pagehel
                                                               // Add name into a map with count
                                                               //  Use concurrency to  increase performamnce
               
               List<Callable><List><String>>> workerThreads = new ArrayList<Callable><List><String>>>();
                                               int size = resultUrls.size();
               for (int start = 0; start < size; start += SUB_LIST_LIMIT) {
                                                                               
                                                               int end = Math.min(start + SUB_LIST_LIMIT, size);                                                                                            
                                                               List<String> subList = resultUrls.subList(start, end);
                                                               
                                                               //For Multi-Threading
                                                               workerThreads.add(new ThreadTask(subList));
                                               }
               try {
                               List<List><String>> threadJsLibraries = new ArrayList<List><String>>();
                               threadJsLibraries = processWorkerThreads(workerThreads);
                               for(List<String> list : threadJsLibraries){
                                               allJsLibraries.addAll(list);
                               }
                                                               } catch (Exception e) {
                                                                               // TODO Auto-generated catch block
                                                                               System.out.println("Inside main: " + e);
                                                               }
                                                               removeDuplicates(allJsLibraries);
                                                               printJsLibraryList();
}
 
Jazib Raza
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Report post to moderator
public static void printJsLibraryList() {
               //jsLibraryList.
               for (Map.Entry<String,Integer> entry : jsLibraryList.entrySet())
       System.out.println(entry.getKey() + " : " + entry.getValue());
}


private static void removeDuplicates(List<String> allJsLibraries) {
               for(String library : allJsLibraries){
                               if(!jsLibraryList.containsKey(library)){
                                               jsLibraryList.put(library,0);
                               }else{
                                               jsLibraryList.put(library, jsLibraryList.get(library) + 1);
                               }
               }
}

public static List<List<String>> processWorkerThreads(
                               List<Callable<List<String>>> workerThreads) throws Exception {
               
               int reqSize = workerThreads.size();
               List<Future<List<String>>> subListResult = new ArrayList<Future<List<String>>>(reqSize);
               List<List<String>> finalResult = new ArrayList<List<String>>(reqSize);

               ThreadPoolExecutor pool = (ThreadPoolExecutor)Executors.newCachedThreadPool();
               CompletionService<List<String>> completionService = new ExecutorCompletionService<List<String>>(
                                               pool);
                               try {
                                               
                                               subListResult = processWorkerThreadsWithCompletionService(workerThreads, completionService);
                                               finalResult = processListOfFutureObjects(subListResult, completionService);
                                               
                               }catch (InterruptedException e) {
                                               System.out.println("Exception occured in processWorkerThreads: " + e);
                                               
                                               if (e.getCause() instanceof RuntimeException)
                                                               throw (RuntimeException) e.getCause().getCause();
                                               else throw e;
                                               
                               } catch (ExecutionException e) {
                                               System.out.println("Exception occured in processWorkerThreads: " + e);
                                               
                                               if (e.getCause() instanceof RuntimeException)
                                                               throw (RuntimeException) e.getCause().getCause();
                                               else throw e;

                               } catch (Exception e) {
                                               System.out.println("Exception occured in processWorkerThreads: " + e);
                                               
                                               if (e.getCause() instanceof RuntimeException)
                                                               throw (RuntimeException) e.getCause().getCause();
                                               else throw e;

                               }finally{
                                               pool.shutdown();
                               }
               return finalResult;
}

private static List<Future<List<String>>> processWorkerThreadsWithCompletionService(
                               List<Callable<List<String>>> workerThreads, CompletionService<List<String>> compService)
                               throws Exception {

               System.out.println("Inside ConcurrencyUtil - processWorkerThreadsWithCompletionService method.");
               int len = workerThreads.size();
               List<Future<List<String>>> workerThreadsResponse = new ArrayList<Future<List<String>>>(
                                               len);
               for (int i = 0; i < len; i++) { <br />                                Callable<List<String>> thread = workerThreads.get(i); <br />                                Future<List<String>> future = compService.submit(thread); <br />                                workerThreadsResponse.add(future); <br />                } <br /> <br />                return workerThreadsResponse; <br /> } <br /> <br /> private static List<List<String>> processListOfFutureObjects( <br />                                List<Future<List<String>>> futureList, CompletionService<List<String>> completionService) <br />                                throws ExecutionException, InterruptedException { <br /> <br />                System.out.println("Inside processListOfFutureObjects method."); <br />                int len = futureList.size(); <br />                List<List<String>> finalResult = new ArrayList<List<String>>(len); <br />                Future<List<String>> completedFuture; <br /> <br />                while (futureList.size() > 0) {

                               try {
                                               // block until a callable completes
                                               completedFuture = completionService.take();
                                               futureList.remove(completedFuture);
                                               // get the result object, if the Callable was able to create it
                                               finalResult.add(completedFuture.get());
                                               
                               } catch (ExecutionException e) {
                                               System.out.println("Exception occured in processListOfFutureObjects: " + e);
                                               continue;
                               } catch (InterruptedException e) {
                                               System.out.println("Exception occured in processListOfFutureObjects: " + e);
                                               continue;
                               }
               }

               return finalResult;
}

}
 
Saloon Keeper
Posts: 12128
258
  • Mark post as helpful
  • send pies
  • Report post to moderator
Please start a new topic if you have another question, and enclose code in code tags, like [code=java]this[/code].
 
If you have a bad day in October, have a slice of banana cream pie. And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic