Skip to content

PubSub creating lots of thread #3720

Closed
Closed

Description

@kakadiyahardik

I am using PubSub with java

Actual behabiour

When i start application (it contains subscriber code) It creates a lot of thread, so after start within few times server will closed

My code for subscriber

ProjectSubscriptionName subName = ProjectSubscriptionName.of(CommonUtils.GCLOUD_PROJECT_ID,
SUBSCRIPTION_ID);

	MessageReceiver receiver = new MessageReceiver() {
		@Override
		public void receiveMessage(PubsubMessage message, AckReplyConsumer consumer) {
			String messageString = message.getData().toStringUtf8();
			System.out.println("message received : " + message.getMessageId());
			consumer.ack();

		}
	};

	Subscriber subscriber = null;
	try {
		ExecutorProvider executorProvider = InstantiatingExecutorProvider.newBuilder().setExecutorThreadCount(1)
				.build();
		subscriber = Subscriber.newBuilder(subName, receiver)
				.setCredentialsProvider(FixedCredentialsProvider.create(credentials))
				.setExecutorProvider(executorProvider).build();

		subscriber.startAsync();
	} catch (Exception e) {
		errorLog.push(e);
	}

Activity

  1. added
    triage me
    on Sep 22, 2018
  2. added
    type: question
    api: pubsub
    priority: p2
    on Sep 24, 2018
  3. removed
    triage me
    on Sep 24, 2018
  4. pongad commented on Sep 24, 2018

    @pongad
    Contributor

    @kakadiyahardik How many threads are you seeing? We create a shared "system executor" to help manage timing-related operations, since we have seen problems where user code is too busy working on messages that "house keeping" operations cannot be scheduled. Does it help if you add .setSystemExecutorProvider(executorProvider)?

  5. kakadiyahardik commented on Sep 25, 2018

    @kakadiyahardik
    Author

    Thank you for your reply, and sorry because there is a mistake in my code so it was created the lots of thread.

  6. pongad commented on Sep 25, 2018

    @pongad
    Contributor

    Looks like the issue is resolved :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

api: pubsubpriority: p2type: question

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions