# Workflow vs Activity

**URL:** <https://community.temporal.io/t/workflow-vs-activity/9826>\
**Category:** Community Support\
**Tags:** java-sdk\
**Created:** [October 13, 2023, 8:47pm UTC](https://community.temporal.io/t/workflow-vs-activity/9826 "2023-10-13T20:47:51Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Joe\_Antony](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/joe_antony/32/4434_2.png) [@Joe\_Antony](https://community.temporal.io/u/Joe_Antony)\
**Post date:** [October 13, 2023, 8:47pm UTC](https://community.temporal.io/t/workflow-vs-activity/9826/1 "2023-10-13T20:47:51Z")

</div>

Hi all,

I was going through [HelloActivity.java](https://github.com/temporalio/samples-java/blob/main/core/src/main/java/io/temporal/samples/hello/HelloActivity.java).

Line no. 68 mentions that “Activities are building blocks of any Temporal Workflow”.  
If that is the case, why do we need to register Activities with the Worker as done in Line no. 157?  
Isn’t registering the Workflow (Line no. 151) enough?

Can an Activity have an independent existence without a Workflow?

Thanks,  
Joe

---

<div class="post-metadata">

**Author:** ![antonio.perez](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/antonio.perez/32/2417_2.png) [@antonio.perez](https://community.temporal.io/u/antonio.perez)\
**Post date:** [October 13, 2023, 11:29pm UTC](https://community.temporal.io/t/workflow-vs-activity/9826/3 "2023-10-13T23:29:03Z")

</div>

Hi @Joe_Antony

Technically you can have separate [workers](https://docs.temporal.io/workers) for [workflows](https://docs.temporal.io/workflows) and [activities](https://docs.temporal.io/activities),

Every time your workflow invokes an activity , like in [line 106](https://github.com/temporalio/samples-java/blob/d6eed631df64160e0a20b54e1fd7664cb20f29c0/core/src/main/java/io/temporal/samples/hello/HelloActivity.java#L106C1-L107C1), the activity task is scheduled in a [taskqueue](https://docs.temporal.io/workers#task-queue) in the server. By default, the activity is scheduled in a taskqueue with the same name as the [workflow taskqueue](https://github.com/temporalio/samples-java/blob/d6eed631df64160e0a20b54e1fd7664cb20f29c0/core/src/main/java/io/temporal/samples/hello/HelloActivity.java#L171) (they have the same name but they are different taskqueues)

Note that you can set the activity taskqueue name in ActivityOptions.

```auto
    private final GreetingActivities activities =
        Workflow.newActivityStub(
            GreetingActivities.class,
            ActivityOptions.newBuilder()
                    .setTaskQueue("my-other-taskqueue")
                    .build());

```

On the other side you have your workers, the once that do the work.

In your worker configuration you have to set at least

- the [taskqueue name](https://github.com/temporalio/samples-java/blob/d6eed631df64160e0a20b54e1fd7664cb20f29c0/core/src/main/java/io/temporal/samples/hello/HelloActivity.java#L144C1-L145C1)
- the workflow and/or activity implementation

Once the worker starts, it opens long poll connections to the server. If there are tasks in the queue the worker is polling from, the server will dispatch a task to the worker, so the worker can execute it.

By registering the activity implementation we are telling the worker what to do with the task (the code it has to execute). Otherwise it won’t know what to do and you will likely see [this error](https://community.temporal.io/t/strange-activity-type-not-registered-errors/4950/3) in the worker.

I would recommend you to go through [this course](https://learn.temporal.io/courses/temporal_101/java) if you have time, which go through this and other concepts.

Other relevant resources:

- [How Temporal Works | Temporal Technologies](https://temporal.io/how-temporal-works)
- [https://youtu.be/6T6zVZHU7\_Q?si=UrtrE4P3b2uiSHh8&t=1559](https://youtu.be/6T6zVZHU7_Q?si=UrtrE4P3b2uiSHh8&t=1559)

Please feel free to reply back with questions if something is unclear.

> Can an Activity have an independent existence without a Workflow?

Can not right now.

Antonio

---

<div class="post-metadata">

**Author:** ![Joe\_Antony](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/joe_antony/32/4434_2.png) [@Joe\_Antony](https://community.temporal.io/u/Joe_Antony)\
**Post date:** [October 15, 2023, 7:01am UTC](https://community.temporal.io/t/workflow-vs-activity/9826/4 "2023-10-15T07:01:13Z")

</div>

Thanks a lot @antonio.perez !  
Really appreciate the effort put into constructing the reply:)
