title: Alternatives for TimeUnit.SECONDS.sleep(1); SpigotMC/ SpigotMC event not running
body: <p>I was trying to make a Minecraft plugin while having this problem, but I thought this would be more of a Java discussion</p>
  <p>So I tried to make a spawner that would spawn a chicken every second (for testing, it would become every minute when I'm done), but while I was testing the event doesn't seem to run (because <code>TimeUnit.SECONDS.sleep()</code> would block the MC thread). So may I have an alternative?
  The delay I'm using as for now is <code>TimeUnit.SECONDS.sleep(*insert some number here*);</code><br> As shown here: <br> <br> Note: I already tried using <code>setTaskTimer</code> and <code>scheduleSyncRepeatingTask</code> as shown in the answers, but they didn't seem to work. Is this an event issue or a <code>spawnEntity</code> issue?</p>
  <pre><code>package com.TheRealBee.Bows.Event10;
  
  
  import org.bukkit.ChatColor;
  import org.bukkit.Material;
  import org.bukkit.entity.EntityType;
  import org.bukkit.event.EventHandler;
  import org.bukkit.event.Listener;
  import org.bukkit.event.block.BlockPlaceEvent;
  
  import java.util.concurrent.TimeUnit;
  
  
  public class EventManager10 implements Listener {
          @EventHandler
  
          public void onNukePlace(BlockPlaceEvent e){
  
  
              // Return if it's not TNT, doesn't have ItemMeta or doesn't have a custom dispaly name
              if(!e.getBlock().getType().equals(Material.GOLD_BLOCK) || !e.getItemInHand().hasItemMeta() || !e.getItemInHand().getItemMeta().hasDisplayName())
                  return;
              // Return if the item display name is not correct
              if(!e.getItemInHand().getItemMeta().getDisplayName().equals(ChatColor.WHITE+&quot;Spawner&quot;))
                  return;
              // Create the explosion
              try {
                  for (int i = 0; i &lt; 300000000; i++) {
                      e.getBlock().getLocation().getWorld().spawnEntity(e.getBlock().getLocation(), EntityType.CHICKEN);
                      TimeUnit.SECONDS.sleep(1);
                  }
              }
              catch(InterruptedException ex)
              {
                  Thread.currentThread().interrupt();
              }
              
          }
  }
  
  </code></pre>