Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a unique thread id for each running threads #34

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading