MiraiForum

    • Register
    • Login
    • Search
    • Popular
    • Recent
    • Unsolved
    • Tags
    • Groups
    • 友情链接

    Solved 配置自动重载

    开发交流
    3
    10
    930
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • guimc233
      guimc233 last edited by

      如何写一个检测到配置文件更改自动重载

      1 Reply Last reply Reply Quote 0
      • guimc233
        guimc233 last edited by

        我目前的做法是新开一个线程来定时刷新配置 但是我感觉这样写不太好

        cssxsh 1 Reply Last reply Reply Quote 0
        • Deleted by  guimc233 guimc233 
        • Restored by  guimc233 guimc233 
        • Topic has been marked as a question  guimc233 guimc233 
        • Mr.喜
          Mr.喜 ⭐2021⭐ last edited by

          虽然我不会Java,但是在C#里有FileSystemWatcher类,能够监控文件创建、删除以及修改,或许Java中也有类似的类

          1 Reply Last reply Reply Quote 0
          • cssxsh
            cssxsh @guimc233 last edited by

            @guimc233

            https://github.com/cssxsh/mirai-administrator/blob/main/src/main/kotlin/xyz/cssxsh/mirai/admin/data/AdminSetting.kt#L54

            可以用文件系统的 WATCH API
            不过你要注意重载时间
            有些编辑器会即时保存,有时格式是不正确的

            guimc233 2 Replies Last reply Reply Quote 0
            • guimc233
              guimc233 @cssxsh last edited by

              @cssxsh 蟹蟹 大概有个思路了
              回头研究一下

              1 Reply Last reply Reply Quote 0
              • Topic has been marked as solved  guimc233 guimc233 
              • Topic has been marked as unsolved  guimc233 guimc233 
              • guimc233
                guimc233 last edited by

                This post is deleted!
                1 Reply Last reply Reply Quote 0
                • guimc233
                  guimc233 @cssxsh last edited by guimc233

                  @cssxsh https://github.com/BakaBotTeam/lgz-bot/blob/master/src/main/kotlin/ltd/guimc/lgzbot/PluginMain.kt#L85-L122
                  我试着这么写 但是好像没有工作

                  1 Reply Last reply Reply Quote 0
                  • guimc233
                    guimc233 last edited by

                    从JProfiler来看 线程是在工作的
                    image.png

                    1 Reply Last reply Reply Quote 0
                    • guimc233
                      guimc233 last edited by

                      好!我自己修好了

                      1 Reply Last reply Reply Quote 0
                      • Topic has been marked as solved  guimc233 guimc233 
                      • cssxsh
                        cssxsh last edited by

                        你这个写法是有问题的

                        1 Reply Last reply Reply Quote 0
                        • 1 / 1
                        • First post
                          Last post
                        Powered by Mamoe Technologies & NodeBB | 友情链接 | 服务监控 | Contact