Skip to content

Commit

Permalink
Merge pull request #34 from SasinduDilshara/refactor-gradle-files
Browse files Browse the repository at this point in the history
Add a unique thread id for each running threads
  • Loading branch information
SasinduDilshara authored Oct 1, 2024
2 parents 780ff5a + 3acca4f commit 3cc620a
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -250,8 +250,7 @@ private void validateFunctionParameterTypes(ExpressionNode expressionNode,
}

private void validateFunctionParameterTypesWithExpType(TypeSymbol expType, Location currentLocation,
SyntaxNodeAnalysisContext ctx, String functionName,
SeparatedNodeList<FunctionArgumentNode> args) {
SyntaxNodeAnalysisContext ctx, String functionName, SeparatedNodeList<FunctionArgumentNode> args) {
switch (expType.typeKind()) {
case ARRAY -> validateFunctionParameterTypesWithArrayType(
(ArrayTypeSymbol) expType, currentLocation, ctx, functionName, args);
Expand Down Expand Up @@ -496,11 +495,8 @@ private void validateTupleMembers(SyntaxNodeAnalysisContext ctx, Location curren
TupleTypeSymbol tupleTypeSymbol = (TupleTypeSymbol) typeSymbol;
tupleTypeSymbol.memberTypeDescriptors().forEach(symbol ->
validateNestedTypeSymbols(ctx, currentLocation, symbol, false));
Optional<TypeSymbol> restSymbol = tupleTypeSymbol.restTypeDescriptor();
if (restSymbol.isPresent()) {
TypeSymbol restSym = restSymbol.get();
validateNestedTypeSymbols(ctx, currentLocation, restSym, false);
}
tupleTypeSymbol.restTypeDescriptor().ifPresent(restSym ->
validateNestedTypeSymbols(ctx, currentLocation, restSym, false));
}

private void validateRecordFields(SyntaxNodeAnalysisContext ctx, Location currentLocation, TypeSymbol typeSymbol) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,15 @@ public final class CsvParser {
private CsvParser() {
}

private static final ThreadLocal<StateMachine> LOCAL_THREAD_STATE_MACHINE
= ThreadLocal.withInitial(StateMachine::new);
// TODO: Add this implementation after creating the object pool implementation
// private static final ThreadLocal<StateMachine> LOCAL_THREAD_STATE_MACHINE
// = ThreadLocal.withInitial(StateMachine::new);

public static Object parse(Reader reader, BTypedesc type, CsvConfig config)
throws BError {
StateMachine sm = LOCAL_THREAD_STATE_MACHINE.get();
// TODO: Add this implementation after creating the object pool implementation
// StateMachine sm = LOCAL_THREAD_STATE_MACHINE.get();
StateMachine sm = new StateMachine();
try {
CsvUtils.validateConfigs(config);
Object convertedValue = sm.execute(reader, TypeUtils.getReferredType(type.getDescribingType()),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicLong;

/**
* Thread pool for data reader.
Expand All @@ -33,6 +34,7 @@ public final class DataReaderThreadPool {
private static final int MAX_POOL_SIZE = 50;
private static final long KEEP_ALIVE_TIME = 60L;
private static final String THREAD_NAME = "bal-data-csv-thread";
private static final AtomicLong THREAD_ID = new AtomicLong(1);
public static final ExecutorService EXECUTOR_SERVICE = new ThreadPoolExecutor(CORE_POOL_SIZE,
MAX_POOL_SIZE, KEEP_ALIVE_TIME, TimeUnit.SECONDS, new SynchronousQueue<>(), new DataThreadFactory());

Expand All @@ -47,7 +49,7 @@ static class DataThreadFactory implements ThreadFactory {
@Override
public Thread newThread(Runnable runnable) {
Thread ballerinaData = new Thread(runnable);
ballerinaData.setName(THREAD_NAME);
ballerinaData.setName(THREAD_NAME + "-" + THREAD_ID.getAndIncrement());
return ballerinaData;
}
}
Expand Down

0 comments on commit 3cc620a

Please sign in to comment.