---
title: "定时任务-gcron与gtimer"
url: "https://goframe.org/docs/components/os-gcron-differ-with-gtimer"
markdown_url: "https://goframe.org/docs/components/os-gcron-differ-with-gtimer.md"
locale: "zh-Hans"
version: "2.10.x(Latest)"
section: "组件列表"
category: "组件列表 / 系统相关 / 定时任务-gcron"
published: "2024-10-21"
updated: "2024-11-11"
description: "GoFrame框架中定时任务模块gcron与定时器模块gtimer的区别。gtimer是高性能模块，适用于各种定时任务场景，包括TCP通信和游戏开发。gcron支持crontab语法，基于gtimer实现，为用户提供了便捷的定时任务管理方式。"
keywords: ["GoFrame", "GoFrame框架", "定时任务", "gcron", "gtimer", "性能模块", "crontab", "时间间隔", "TCP通信", "游戏开发"]
---

# 定时任务-gcron与gtimer

## `gcron` 与 `gtimer` 区别

[定时任务-gcron](https://goframe.org/docs/components/os-gcron) 与 [定时器-gtimer](https://goframe.org/docs/components/os-gtimer) 区别:

- `gtimer` 属于高性能模块，是框架核心模块，构建任何定时任务的基础，任何方法操作耗时均在 `纳秒` 级别。
- `gtimer` 可适用于任何的定时任务场景中，例如: TCP通信、游戏开发等场景。
- `gcron` 支持经典的 `crontab` 形式的定时任务语法，最小时间设定间隔为 `秒`。
- `gcron` 底层实现基于 `gtimer`。

| 相似模块 | 说明 | 性能 | 类Linux Crontab模式 | 底层实现 |
| --- | --- | --- | --- | --- |
| [定时任务-gcron](https://goframe.org/docs/components/os-gcron) | 定时任务。<br />较上层封装，时间刻度以自然秒为单位。 | 一般 | 支持 | 基于 `gtimer` |
| [定时器-gtimer](https://goframe.org/docs/components/os-gtimer) | 定时器。<br />底层组件，时间刻度以时间槽为单位（时间槽可自定义）。 | 高效 | 不支持 | 基于 `PriorityQueue` 数据结构自实现 |
